This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Limitations to Shared Library Support

MATLAB Supports C Library Routines

The MATLAB® shared library interface supports C library routines only. Most professionally written libraries designed to be used by multiple languages and platforms work fine. For more information, see Call C Functions in Shared Libraries.

Many noncommercial libraries or libraries that have only been tested from C++ have interfaces that are not usable and require modification or an interface layer. In this case, we recommend using MEX files.

Loading C++ Libraries

The shared library interface does not support C++ classes or overloaded functions elements. Use the MATLAB C++ interface instead. For more information, see C++ Libraries.

Limitations Using printf Function

MATLAB does not display the output of the C printf function to the command window.

Bit Fields

You can modify a bit field declaration by using type int or an equivalent. For example, if your library has the following declared in its header file:

int myfunction();

struct mystructure
{
    /* note the sum of fields bits */
    unsigned field1 :4;
    unsigned field2 :4;
};

edit the header file and replace it with:

int myfunction();

struct mystructure
{
    /* field 8 bits wide to be manipulated in MATLAB */
    /* A char is 8 bits on all supported platforms */
    char allfields; 
};

After editing the source code, rebuild the library. It is then possible to access the data in the two fields using bit masking in MATLAB.

Enum Declarations

char definitions for enum are not supported. In C, a char constant, for example 'A', is automatically converted to its numeric equivalent (65). MATLAB does not convert constants. To use this type of enum, edit the header file by replacing 'A' with the number 65 (int8('A') == 65). For example, replace:

enum Enum1 {ValA='A',ValB='B'};

with:

enum Enum1 {ValA=65,ValB=66};

then rebuild the library.

Unions Not Supported

Unions are not supported. As a workaround, modify the source code taking out the union declaration and replacing it with the largest alternative. Then, to interpret the results, write MATLAB code as needed. For example, edit the source code and replace the following union:

struct mystruct
{
    union 
    {
       struct {char byte1,byte2;};
	       short word;
    };
};

with:

struct mystruct 
{
    short word;
};

where on a little-endian based machine, byte1 is mod(f,256), byte2 is f/256, and word=byte2*256+byte1. After editing the source code, rebuild the library.

Compiler Dependencies

Header files must be compatible with the supported compilers on a platform. For an up-to-date list of supported compilers, see Supported and Compatible Compilers. You cannot load external libraries with explicit dependencies on other compilers.

Limitations Using Pointers

Function Pointers

The shared library interface does not support library functions that work with function pointers.

Multilevel Pointers

Limited support for multilevel pointers and structures containing pointers. Using inputs and outputs and structure members declared with more than two levels of indirection is unsupported. For example, double ***outp translated to doublePtrPtrPtr is not supported.

Functions with Variable Number of Input Arguments Not Supported

The shared library interface does not support library functions with variable number of arguments, represented by an ellipsis (...).

You can create multiple alias functions in a prototype file, one for each set of arguments used to call the function. For more information, see MATLAB Prototype Files.

Related Topics