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

2 ビュー (過去 30 日間)
Craig
Craig 2012 年 6 月 1 日
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 Center および File ExchangeWrite 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