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

1 次查看(过去 30 天)
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?

采纳的回答

Ken Atwell
Ken Atwell 2012-6-3
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 个评论
Craig
Craig 2012-6-4
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Write C Functions Callable from MATLAB (MEX Files) 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by