Why do I receive the error "ld: library not found for -lmex" when trying to compile a MEX function manually?

I am trying to use a supported compiler to compile my C code into a MEX file, instead of the "mex" command. I receive the following error when I try to compile:
ld: library not found for -lmex
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Why do I get this error and how can I fix it?

 Accepted Answer

We recommend that you use the "mex" command to compile MEX files, but it is possible to compile MEX files using a supported compiler instead to exercise more control over the build process. If you would like to learn more about the "mex" command, please refer to the documentation page below:
The error occurs because the linker cannot find the location of dynamically linked libraries, such as libmex, libmat, libeng, or libmx. The location of these libraries depends on the compiling computer's operating system. Please refer to the following documentation link to find out where required libraries are on your computer:
You can include these paths in the search path for the linker by including them in the compilation instruction using the "-I" flag. Please see the following documentation link for an example of specifying a path to include files:
Do not add a space between the "I" and the path to include.
To learn more about compiling MEX files manually, please refer to the documentation link below:

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!