如何使用相对路径从共享库链接到共享库?

发布于 2024-09-28 03:31:56 字数 245 浏览 1 评论 0原文

我正在开发一个 Firefox 插件,它使用外部库在浏览器上渲染 3D 图形。

问题是我希望插件使用包含它的外部库而不更改 LD_LIBRARY_PATH 变量。
这些库安装在相对于插件的位置(也是共享库),而实际的可执行文件(即浏览器)可以完全位于其他位置。

我正在 Ubuntu 上测试(Windows 版本的插件没有问题) 我的依赖项是 OpenSceneGraph 库,静态编译将使插件变得非常大(如果有另一个则不是一个选项)。

I'm working on a Firefox plugin that uses external libraries to render 3D graphics on the browser.

The problem is that I want the plugin to use external libraries packed with it without changing the LD_LIBRARY_PATH variable.
The libraries are installed in a position relative to the plugin (a shared library too), while the actual executable (i.e. the browser) can be located somewhere entirely else.

I'm testing it on Ubuntu (no problem at Windows version of the plugin)
My dependencies are OpenSceneGraph libraries and static compilation will make the plugin really big (not an option if there is another one).

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

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

发布评论

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

评论(3

风渺 2024-10-05 03:31:56

链接时使用 rpath 选项并指定“特殊”路径 $ORIGIN

示例:

-Wl,-R,'$ORIGIN/../lib'

这是一个详细说明如何使用 $ORIGIN 的网站:
http://www.itee.uq.edu.au/~daniel/using_origin/

Use the rpath option when linking and specify the 'special' path $ORIGIN.

Example:

-Wl,-R,'$ORIGIN/../lib'

Here's a site that elaborates on using $ORIGIN:
http://www.itee.uq.edu.au/~daniel/using_origin/

囍笑 2024-10-05 03:31:56

您可以在编译期间使用 -L 标志来指定链接器可以找到共享对象的相对路径。

如果您已经生成了 lib,则可以通过直接调用 ld 命令进行链接。

提示:您可以使用unix命令nm轻松检查lib中是否定义了某些符号。这是检查链接是否良好的有用方法。

(如果我是你,我只会像你在帖子中所说的那样临时更改LD_LIBRARY_PATH。你为什么不想这样做呢?)

You could maybe use the -L flag during the compilation to specify the relative path where the linker can find your shared objects.

If you have already generated your lib, you can link by directly invoking the ldcommand.

Tips : You can easily check if some symbols are defined in a lib using the unix command nm. This is a useful way to check that the linking is well-done.

(If I were you, I would just change temporaly the LD_LIBRARY_PATH as you said in your post. Why don't you want to do this ?)

牵你的手,一向走下去 2024-10-05 03:31:56

出于安全原因使用相对 rpath 是错误的,

您应该使用 libdl 函数(dlopen 等)

It's wrong to use relative rpath for security reason,

You should use libdl functions (dlopen, etc)

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