Mex Link Failure: Undefined Symbols for Architecture

2 visualizaciones (últimos 30 días)
Adriano Martinelli
Adriano Martinelli el 13 de Mzo. de 2017
Respondida: Saurabh el 13 de Mayo de 2025
Hi, I run Matlab 2016b on Mac 10.12.3, compiling with Xcode 7.3.1. I'm trying to make a model with IQMmakeMEXmodel but when I run it, it states:
Error using mex
Undefined symbols for architecture x86_64:
"_CVODEmex25", referenced from:
_mexFunction in MEXmodel.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Error in mexcompileIQM (line 21)
eval(sprintf('mex -O -I''%s'' %s.c ''%s'';',includefolder,filename,libpath));
Error in IQMmakeMEXmodel (line 341)
mexcompileIQM(MEXfunctionName);
Any idees how to solve this one?

Respuestas (1)

Saurabh
Saurabh el 13 de Mayo de 2025
I understand that there was an issue during the linking process when tried to compile a MEX file using MATLAB’s ‘mex’ command on Mac system.
The error message encountered here:
Error using mex
Undefined symbols for architecture x86_64:
"_CVODEmex25", referenced from:
_mexFunction in MEXmodel.o
indicates that the linker cannot find the symbol ‘_CVODEmex25’ during the compilation of MEX file. This typically occurs when the required library containing this symbol is not linked correctly.
Potential Causes and Solutions:
1. Missing or Incorrect Library Linking
The symbol '_CVODEmex25' suggests that code depends on the CVODE library from the SUNDIALS suite. If this library is not linked correctly, this error will be encountered.
Solution:
  • Ensure the library is installed: Verify that the CVODE library is installed on the system.
  • Link the library during compilation: When compiling the MEX file, you need to link against the CVODE library. This can be done by adding the '-lcvode' flag to 'mex' command, and specifying the library path with -L. For example:
mex -I/path/to/include -L/path/to/lib -lcvode MEXmodel.c
  • Replace /path/to/include and /path/to/lib with the actual paths to the CVODE headers and library files.
2. Incompatible Architecture Between MATLAB and Libraries:
  • If there's a mismatch between the architecture of MATLAB and the compiled libraries (e.g., MATLAB is 64-bit, but the library is 32-bit), this error will be encountered.
Solution:
  • Check MATLAB's architecture: In MATLAB, run:
mexext
  • This will return something like mexa64, indicating a 64-bit architecture.
  • Check library architecture: In the terminal, run:
file /path/to/libcvode.dylib
  • Ensure it matches MATLAB's architecture.
  • Recompile the library if necessary: If there's a mismatch, recompile the CVODE library to match MATLAB's architecture.
3. Incorrect mex Configuration
  • MATLAB uses a configuration file to determine how to compile MEX files. If this configuration is incorrect, it can lead to linking errors.
Solution:
  • Run mex -setup: In MATLAB, execute:
mex -setup
  • This will guide through selecting the appropriate compiler. Ensure that the selected compiler is compatible with system and MATLAB version.
4. Missing mexFunction Definition
  • Every MEX file must define a 'mexFunction', which serves as the entry point. If this function is missing, you'll encounter linking errors.
Solution:
  • Check source code: Ensure that 'MEXmodel.c' file contains the following function:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
// code here
}
  • If this function is missing, add it to the source code.
I hope this helps!

Categorías

Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by