Main Content

Troubleshooting C++ Library Definition Issues

MATLAB Did Not Create MLX Definition File

Sometimes, the content of library files exceeds limits, which causes MATLAB® to create only an M file but not an MLX file. Search your output folder for a definition file of the form definelibName.m and edit the contents as you do the MLX version.

Cannot Open or Too Slow to Load MLX Definition File

If you have performance issues opening the MLX file, then you can use the corresponding definelibName.m file instead. First delete the MLX file, and then open the .m file in MATLAB Editor.

Shape Value Not Found

When you use an argument to define the shape for another argument, you must define the argument in the C++ function signature. In the example Generated Library Definition MLX File, suppose that you define the shape of argument in as argument inb:

defineArgument(taskDefinition, "in", "clib.array.libname.Int", "input", "inb");

The C++ signature for function task does not have an argument inb.

void task(int* in, double* ind, int sz, char const* inc)

For more information about SHAPE values, see Define Missing SHAPE Parameter.

Invalid Shape Value Type

When you use an argument to define the shape for another argument, you must consider the types for both arguments. In the example Generated Library Definition MLX File, suppose that you define argument inc as a null-terminated string:

defineArgument(taskDefinition, "inc", "string", "input", "nullTerminated");

If you define the shape of argument ind as argument inc, MATLAB displays an error because a string cannot be used for a numeric type.

defineArgument(taskDefinition, "ind", "clib.array.libname.Double", "input", "inc");

For more information about SHAPE values, see Define Missing SHAPE Parameter.

Why Is a Function or a Type Missing from the Definition File?

If a library contains any unsupported language features or data types, then the functionality is not included in the library definition file.

Generated Library Definition MLX File

For information about the error messages, refer to this example. The C++ signature is:

void task(int * in, double * ind, int sz, char const * inc)
%taskDefinition = addFunction(libDef, ...
%    "void task(int * in,double *  ind,int sz,char const * inc)", ...
%    "MATLABName", "clib.libname.task", ...
%    "Description", "clib.libname.task    Representation of C++ function task."); 
% Modify help description values as needed.
%defineArgument(taskDefinition, "in", "clib.array.libname.Int", "input", <SHAPE>); 
% <MLTYPE> can be "clib.array.libname.Int",or "int32"
%defineArgument(taskDefinition, "ind", "clib.array.libname.Double", "input", <SHAPE>); 
% <MLTYPE> can be "clib.array.libname.Double", or "double"
%defineArgument(taskDefinition, "sz", "int32");
%defineArgument(taskDefinition, "inc", <MLTYPE>, "input", <SHAPE>); 
% <MLTYPE> can be "clib.array.libname.Char","int8","string", or "char"
%validate(taskDefinition);

Build Error undefined reference or unresolved external symbol

When you build an interface by using the clibgen.generateLibraryDefinition or clibgen.buildInterface functions, the compiler might display error messages about an undefined reference or an unresolved external symbol. These errors often occur when you forget to provide information about shared library files. To include shared library files, use the Libraries name-value argument.

If you already called the clibgen.generateLibraryDefinition function, you can edit the library definition file definelibname.mlx to fix the build error. Search for the OutputFolder and Libraries section and fill in or modify the libDef.Libraries variable. Be sure to specify the full path and the library name. Save the file, then rerun the build function.

Related Topics