Borrar filtros
Borrar filtros

Trouble compiling c++ examples that read .mat files on osx

2 visualizaciones (últimos 30 días)
When compiling one of the examples for reading mat files in c++ I get the following result
bash-3.2$ gcc -I /Applications/MATLAB_R2012a.app/extern/include/ matdgns.c
matdgns.c: In function 'diagnose':
matdgns.c:81: warning: format '%d' expects type 'int', but argument 3 has type 'mwSize'
matdgns.c:81: warning: format '%d' expects type 'int', but argument 3 has type 'mwSize'
matdgns.c:112: warning: format '%d' expects type 'int', but argument 3 has type 'mwSize'
matdgns.c:112: warning: format '%d' expects type 'int', but argument 3 has type 'mwSize'
Undefined symbols for architecture x86_64:
"_matOpen", referenced from:
_diagnose in ccAC9eU9.o
"_matGetDir", referenced from:
_diagnose in ccAC9eU9.o
"_mxFree", referenced from:
_diagnose in ccAC9eU9.o
"_matClose", referenced from:
_diagnose in ccAC9eU9.o
"_matGetNextVariableInfo", referenced from:
_diagnose in ccAC9eU9.o
"_mxGetNumberOfDimensions_730", referenced from:
_diagnose in ccAC9eU9.o
"_mxIsFromGlobalWS", referenced from:
_diagnose in ccAC9eU9.o
"_mxDestroyArray", referenced from:
_diagnose in ccAC9eU9.o
"_matGetNextVariable", referenced from:
_diagnose in ccAC9eU9.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status
So it looks like the linker just can't find the libmat.dylib library, but I have set up my environment as described in http://www.mathworks.com/help/techdoc/matlab_external/f19027.html so the command "echo $DYLD_LIBRARY_PATH" results in
bash-3.2$ echo $DYLD_LIBRARY_PATH
/Applications/MATLAB_R2012a.app/bin/maci64:/Applications/MATLAB_R2012a.app/sys/os/maci64:/Applications/MATLAB_R2012a.app/bin/maci64:
Can anyone see what I'm missing?

Respuesta aceptada

Ken Atwell
Ken Atwell el 3 de Jun. de 2012
The doc you indicated assumes you are building from within MATLAB, using the MEX command. You're building with GCC from the command-line. You need to include the MATLAB libraries on your command line (MEX does this for you). Include the following in your gcc invocation:
-lmx -lmex -lmat
This may be enough. If not, trying building your engine application with "mex" inside MATLAB. Use the -v switch to get verbose output, which will help you determine the exact gcc command line(s) needed to build outside of MATLAB.
  1 comentario
Craig
Craig el 4 de Jun. de 2012
Thanks for the start, I just needed to add the -lmx and -lmat and -L/Applications/MATLAB_R2012a.app/bin/maci64/ as explained on http://www.alecjacobson.com/weblog/?p=924

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by