开发者

relative paths for shared libraries

开发者 https://www.devze.com 2023-03-30 07:56 出处:网络
I\'m working with JNI. I have a wrapper library (wrapper.so) that uses two shared libraries: one.so and two.so

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号