I'm trying to learn how to build and use dynamic library in a c++ program. Everything is fine and my program run well when I launch it from Terminal (I'm on a mac OS X El Capitan). Surprisingly that's not the case when I try to launch it by clicking on the executable. I get a dyld: Library not loaded: liblibrary.so
, Reason: image not found
error.
All my files are in a same repertory. I build them with commands :
g++ -c -fPIC A.cpp
g++ -c -fPIC B.cpp
g++ -shared -fPIC A.o B.o -o library.so
g++ main.cpp library.so -o Program
Thank's in advance for your help.
I tried the following solutions :
- Add a PATH, both in
LD_LIBRARY_PATH
andDYLD_LIBRARY_PATH
- Change the library extention :
library.so
orlibrary.dylib
- Add an rpath
g++ main.cpp library.so -Wl,-rpath,. -o Program
andg++ main.cpp library.so -Wl,-rpath,$HOME/my_dir -o Program