relative paths for shared libraries
I'm working with JNI. I have a wrapper library (wrapper.so) that uses two shared libraries: one.so and two.so
Everything works fine. All *.so are in the lib folder, inside the program folder.
The problem is, if I copy this folder to another computer I get linking problems.
Let's say I run this on a machine user2 (/h开发者_StackOverflow中文版ome/user2/program), and I compiled in a machine user1 (/home/user1/program), I get the linking error:
UnsatisfiedLinkError: /home/user1/program/lib/one.so
How I can make the linking of the libraries relative to the parent program folder (like, search for this_foler/lib ??
I'm compiling like:
g++ -c -o src/wrapper.o src/wrapper.c
g++ -shared -o wrapper.so src/wrapper.o one.so two.so
How I can make the linking of the libraries relative to the parent program folder
Depends on your operating system. On Linux, this will probably work:
g++ -shared -o wrapper.so -Wl,-rpath='$ORIGIN' src/wrapper.o one.so two.so
Note: single quotes are important in above command.
精彩评论