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
dzhioev
  • 66
  • 5
  • 17

1 Answers1

1

At runtime, DYLD_LIBRARY_PATH helps dynamic linker to locate libraries from non-standard directories.

In your case, you are still in compilation phase. For gcc to know about these extra directories to search, you could use -L switch.

e.g.

gcc ab.c -L/opt/local/lib -lgmp
Icarus3
  • 2,148
  • 11
  • 20