Why does Matlab link to wrong library?

1 回表示 (過去 30 日間)
Andrew Cox
Andrew Cox 2017 年 4 月 25 日
回答済み: Ankita Nargundkar 2017 年 5 月 12 日
I'm compiling a C++ file that uses the GSL libraries on a Mac (Apple OS 10.12.4). Here's the compilation command:
mex GslInteg_CR3BP.cpp ../SPICE_MAC/cspice.a -I../include -I../SPICE_MAC/src/cspice -L../libmac -lgsl -lgslcblas
The directory structure is setup like:
  • CPP_fcns
  • include
  • libmac
  • SPICE_MAC
The GslInteg_CR3BP.cpp file is located within the CPP_fcns directory and the mex command is run from within that directory. Within the libmac folder are several static and dynamic libraries for GSL: libgsl and libgslcblas. When I run the compilation command, everything completes successfully. However, when I try to use the compiled executable I receive an error:
Invalid MEX-file
...
Library not loaded: /usr/local/lib/libgsl.0.dylib
...
Reason: image not found
I can confirm that the executable is linked incorrectly by checking with otool:
otool -L GslInteg_CR3BP.mexmaci64
/System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 22.0.0)
/usr/local/lib/libgsl.0.dylib (compatibility version 18.0.0, current version 18.0.0)
/usr/local/lib/libgslcblas.0.dylib (compatibility version 1.0.0, current version 1.0.0)
@rpath/libmx.dylib (compatibility version 0.0.0, current version 0.0.0)
@rpath/libmex.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 307.5.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1238.50.2)
I don't understand why it's linking to files in /usr/local/lib. The GSL libraries do not exist there (I checked), nor are the libraries in ../libmac symbolically linked to any libraries in /usr/local/lib. I used to have GSL installed there, but I removed it. However, how is the compiler executing without linking errors if the libraries the *.mexmaci64 file are linked to do not exist? How do I force the compiler to link to the libraries in ../libmac?

回答 (1 件)

Ankita Nargundkar
Ankita Nargundkar 2017 年 5 月 12 日
Contact MathWorks technical support for further assistance.

カテゴリ

Help Center および File ExchangeCall C++ from MATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by