Compiling MEX File Fails
Build Example Files
Can you compile and run the timestwo.c
or
timestwo.f
example files? See Build C MEX Function
or Build Fortran MEX File.
Use Supported Compiler
Are you using a supported compiler? For an up-to-date list of supported compilers, see Supported and Compatible Compilers.
File Not Found on Windows
The mex
command cannot find files located in folder names
that contain non-ASCII characters.
Linux gcc -fPIC
Errors
If you link a static library with a MEX file, which is a shared library, you might
get an error message containing the text recompile with -fPIC
.
Try compiling the static library with the -fPIC
flag to create
position-independent code. For information about using the gcc compiler, see https://www.gnu.org/. For an up-to-date list of supported compilers, see Supported and Compatible Compilers.
Compiler Errors in Fortran MEX Files
When you compile a Fortran MEX file using a free source form format, MATLAB® displays an error message of the following form:
Illegal character in statement label field
mex
supports the fixed source form. For information about the
difference between free and fixed source forms, refer to a FORTRAN 77 Language
Reference manual.
Syntax Errors Compiling C/C++ MEX Files on UNIX
If MATLAB header files generate multiple syntax errors when you compile your code on UNIX® systems, you might be using a non-ANSI® C compiler.
The most common configuration problem creating C/C++ MEX files on UNIX systems involves using a non-ANSI C compiler, or failing to pass a compiler flag telling it to compile ANSI C code.
One way to know if you have this type of configuration problem is if the MATLAB header files generate multiple syntax errors when you compile your code. If necessary, obtain an ANSI C compiler.