共享库的相对路径

发布于 2024-12-01 12:41:58 字数 487 浏览 4 评论 0原文

我正在与 JNI 合作。我有一个包装器库(wrapper.so),它使用两个共享库:one.so 和two.so

一切正常。所有 *.so 都位于程序文件夹内的 lib 文件夹中。

问题是,如果我将此文件夹复制到另一台计算机,则会出现链接问题。

假设我在机器 user2 (/home/user2/program) 上运行它,并在机器 user1 (/home/user1/program) 上编译,我收到链接错误:

UnsatisfiedLinkError: /home/user1/program/lib /one.so

我如何使库相对于父程序文件夹进行链接(例如,搜索 this_foler/lib ?

我正在编译如下:

g++ -c -o src/wrapper.o src/wrapper.c
g++ -shared -o wrapper.so src/wrapper.o one.so 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 (/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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

中二柚 2024-12-08 12:41:58

如何使库链接到父程序文件夹

取决于您的操作系统。在 Linux 上,这可能会起作用:

g++ -shared -o wrapper.so -Wl,-rpath='$ORIGIN' 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文