This is machine translation

Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

Translate This Page

MathWorks Machine Translation

The automated translation of this page is provided by a general purpose third party translator tool.

MathWorks does not warrant, and disclaims all liability for, the accuracy, suitability, or fitness for purpose of the translation.

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 Functions in Shared Libraries.

Many homegrown 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.

Workarounds for Loading C++ Libraries

The shared library interface does not support C++ classes or
overloaded functions elements. However, if you have source code for
the library, you can apply one of the following strategies to load
a C++ library using loadlibrary. After editing
the source code, rebuild the library.

Declare Functions as extern "C"

For example, the following function prototype from the file shrlibsample.h shows
the syntax to use for each function:

Add Module Definition File in Visual Studio

While building the DLL from C++ code in Microsoft®
Visual Studio®,
add a Module Definition File (.DEF) in the project. At a minimum,
the DEF file must contain the following module-definition statements:

The first statement in the file must be the LIBRARY
statement.

The EXPORTS statement lists the names and, optionally,
the ordinal values of the functions exported by the DLL.

For example, if a DLL exports functions multDoubleArray and addMixedTypes, module.def contains:

LIBRARY
EXPORTS
multDoubleArray
addMixedTypes

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:

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:

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
the Supported
and Compatible Compilers website. 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.