Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 (/home/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
like image 631
lcguida Avatar asked Aug 23 '11 16:08

lcguida


1 Answers

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.

like image 89
Employed Russian Avatar answered Sep 18 '22 02:09

Employed Russian