如何链接本地目录中的共享库,OSX 与 Linux

发布于 2024-09-30 03:04:11 字数 391 浏览 1 评论 0原文

我在沙箱目录中安装了一些共享/动态库。我正在构建一些与库链接的应用程序。我遇到了 OSX 和 Linux 在这方面的差异,我不确定(最好的)解决方案是什么。

在 OSX 上,库本身的位置被记录到库中,因此,如果您的应用程序链接到它,则可执行文件知道在运行时在哪里查找库。这与我的沙箱预期的一样,因为可执行文件看起来在那里,而不是系统范围的安装路径。

在 Linux 上我无法让它工作。显然,图书馆位置并不存在于图书馆本身中。据我了解,您必须将包含库的文件夹添加到 /etc/ld.so.conf 并通过运行 ldconfig 重新生成 ld 缓存。

这似乎对我不起作用,因为我的库位于用户主目录内。看起来 ldconfig 不喜欢这样,这实际上是有道理的。

我该如何解决这个问题?我不想将库移出我的沙箱。

I have some shared/dynamic libraries installed in a sandbox directory. I'm building some applications which link agains the libraries. I'm running into what appears to be a difference between OSX and Linux in this regard and I'm not sure what the (best) solution is.

On OSX the location of library itself is recorded into the library, so that if your applications links against it, the executable knows where to look for the library at runtime. This works like expected with my sandbox, because the executable looks there instead of system wide install paths.

On Linux I can't get this to work. Apparently the library location is not present in the library itself. As I understand it you have to add the folders which contain libraries to /etc/ld.so.conf and regenerate the ld cache by running ldconfig.

This doesn't seem to do the trick for me because my libraries are located inside a users home directory. It looks like ldconfig doesn't like that, which makes sense actually.

How can I solve this? I don't want to move the libraries out of my sandbox.

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

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

发布评论

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

评论(2

野侃 2024-10-07 03:04:11

在 Linux 上,运行程序时将环境变量 LD_LIBRARY_PATH 设置为您的沙箱目录。

(我记得曾使用标志 -R 在二进制文件中包含库路径,但它要么已从 gcc 中删除,要么仅在 BSD 系统上可用。)

On Linux, run your program with the environment variable LD_LIBRARY_PATH set to your sandbox dir.

(I remember having used a flag -R to include library paths in the binary, but either it has been removed from gcc or it was only available on BSD systems.)

滥情哥ㄟ 2024-10-07 03:04:11

在 Linux 上,您应该将 LD_RUN_PATH 设置为您的沙箱目录。这比设置 LD_LIBRARY_PATH 更好,因为您是在链接时告诉链接器库的位置,而不是在运行时告诉共享库加载器强>。

请参阅:链接

On Linux you should set LD_RUN_PATH to your sandbox dir. This is better than setting LD_LIBRARY_PATH because you're telling the linker where the library is at link time, rather than telling the shared library loader at run time.

See: Link

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