如何使用相对路径从共享库链接到共享库? [英] How to link to shared lib from shared lib with relative path?

查看:202
本文介绍了如何使用相对路径从共享库链接到共享库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个Firefox插件,该插件使用外部库在浏览器上呈现3D图形.

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

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

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.

我正在Ubuntu上对其进行测试(Windows版本的插件没有问题) 我的依赖项是OpenSceneGraph库,静态编译会使插件真正变大(如果有另一个插件,则不是一个选择).

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).

推荐答案

在链接时使用rpath选项,并指定特殊"路径 $ ORIGIN .

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

示例:

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

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

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

这篇关于如何使用相对路径从共享库链接到共享库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆