Symbol not found: _mexPrintf when using mex executable

22 visualizaciones (últimos 30 días)
Robert
Robert el 17 de Abr. de 2024 a las 13:35
Editada: Robert el 17 de Abr. de 2024 a las 14:42
Hi, I am using a Sonoma 14.3.1 macOs with Apple M1 Pro. I managed to compile a c++ function using mex (It involves libraries such as boost and openMP which I struggled to properly link but ultimately succeedded), but when I run the mex executable in Matlab it crashes. Following the advice in https://es.mathworks.com/matlabcentral/answers/212716-how-do-i-troubleshoot-a-matlab-crash-associated-with-a-custom-mex-function I used 'feval' and a mexhost to debug and try to see what is going on without matlab crashing on me all the time. Here is the code snippet of the function call using feval:
mh = mexhost;
[preds, probs]=feval(mh,'generate_path_structure',A,tols);
where "A" is a sparse matrix with 1s and "tols" is a vector of doubles. Running the matlab code using feval displays the following error message:
Invalid C++ MEX-file 'generate_path_structure': dlopen(/Users/robertbenassai/Documents/UOC/MCM/mcm/generate_path_structure.mexmaca64, 0x0006):
Symbol not found: _mexPrintf
Referenced from: <C58C4F04-7EBD-313D-A9BD-61548F72625D> /Users/robertbenassai/Documents/UOC/MCM/mcm/generate_path_structure.mexmaca64
Expected in: <A1867563-F598-3005-B8E0-8FFDD5D68CA6> /Applications/MATLAB_R2023b.app/interprocess/bin/maca64/mex/libmex.dylib
Which I think happens because Matlab doesn't find the libmex.dylib library. Before having a "Symbol not found" with 'mexPrintf' I had the same issue with 'mexErrMsgIdAndTxt' but I was able to comment the lines where it appeared, which I can't do with mexPrintf because it is probably included in another mex function I am using.
I have tried changing the DYLD_LIBRARY_PATH variable to add the path /Applications/MATLAB_R2023b.app/interprocess/bin/maca64/mex/libmex.dylib but I haven't succeeded.
My compilation line is:
mex -largeArrayDims generate_path_structure.cpp -I"/opt/homebrew/include" -I"/Applications/MATLAB_R2023b.app/extern/include" -L"/opt/homebrew/lib" -L"/Applications/MATLAB_R2023b.app/bin/maca64" -lboost_system -lboost_filesystem -lboost_graph CXXFLAGS="\$CXXFLAGS -std=c++20 -fopenmp" LDFLAGS="\$LDFLAGS -Xpreprocessor -fopenmp"
And compiles just fine. I've also tried to compile linking /Applications/MATLAB_R2023b.app/interprocess/bin/maca64/mex but it gives the following error on compilation related to mexPrintf:
Error using mex
Undefined symbols for architecture arm64:
"_mexPrintf", referenced from:
_mexFunction in generate_path_structure.o
_mexFunction.omp_outlined in generate_path_structure.o
ld: symbol(s) not found for architecture arm64
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
I am quite new to Matlab and I would really appreciate if someone could help me find the reason of the issue. I am also not a computer scientist so I'm sorry for being messy and incorrect in my question, my knowledge is pretty limited...
Thank you beforehand

Respuestas (0)

Categorías

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

Productos


Versión

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by