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

2 views (last 30 days)
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?

Accepted Answer

Ken Atwell
Ken Atwell on 3 Jun 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 Comment
Craig
Craig on 4 Jun 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

Sign in to comment.

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!