1

I can't link my program with shared library located in non-standart OSX lib directory. I've got this library from MacPorts and it's located in /opt/local/lib:

$ ls /opt/local/lib/libgmp*
/opt/local/lib/libgmp.10.dylib  /opt/local/lib/libgmpxx.4.dylib
/opt/local/lib/libgmp.a         /opt/local/lib/libgmpxx.a
/opt/local/lib/libgmp.dylib     /opt/local/lib/libgmpxx.dylib
/opt/local/lib/libgmp.la        /opt/local/lib/libgmpxx.la

I've found that one can use DYLD_FALLBACK_LIBRARY_PATH, but it not works for me:

$ DYLD_LIBRARY_PATH=/opt/local/lib gcc ab.c -lgmp
ld: library not found for -lgmp
collect2: ld returned 1 exit status
4

1 回答 1

1

在运行时,DYLD_LIBRARY_PATH 帮助动态链接器从非标准目录中定位库。

就您而言,您仍处于编译阶段。要让 gcc 了解这些要搜索的额外目录,您可以使用 -L 开关。

例如

gcc ab.c -L/opt/local/lib -lgmp
于 2013-07-24T10:16:15.287 回答