如何构建没有硬编码的完全依赖关系路径的共享库(.so)?

编程入门 行业动态 更新时间:2024-10-28 16:20:58
本文介绍了如何构建没有硬编码的完全依赖关系路径的共享库(.so)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要建立两个第三方共享库,所以他们的.so文件将被其他项目重用。然而,在构建之后,这些库之一包含到另一个的硬编码路径。此路径在其他计算机上无效,并导致链接器警告。如何防止完整路径嵌入到生成的.so文件中?

I need to build two 3rd party shared libraries, so their .so files will be reused by other projects. However, after build one of these libraries contains hardcoded path to another. This path is invalid on other machines and causes linker warnings. How can I prevent the full path from being embedded in the resulting .so files?

详细信息:

库来源:〜/ dev / A 第二个库来源:〜/ dev / B

两者都有 configure 脚本来生成make文件。库 B 取决于 A 。所以,首先我建立 A :

Both of them have configure script to generate make files. Library B depends on A. So, first I build A:

$ ~/dev/A/configure --prefix=~/dev/A-install $ make && make install

然后我建立 B :

$ ~/dev/B/configure --prefix=~/dev/B-install --with-A=~/dev/A-install $ make && make install

然后我要上传〜/ dev / A -install 和〜/ dev / B-install 到我们的文件服务器,以便其他团队和构建机器可以使用二进制文件。但是当他们尝试使用 B 时,它们会获得链接器警告:

Then I want to upload the contents of ~/dev/A-install and ~/dev/B-install to our file server, so other teams and build machines can use the binaries. But they get linker warnings when they try to use B:

/usr/bin/ld: warning: libA.so.2, needed by /.../deps/B/lib/libB.so, not found (try using -rpath or -rpath-link)

当我运行 ldd libB.so

When I run ldd libB.so it gives:

... libA.so.2 => /home/alex/dev/A-install/lib/libA.so.2

显然,此路径

如何从 libB.so

感谢。

推荐答案

code> - 前缀的值将在运行时环境中对这两个包有效。

You have to use --prefix value that will be valid in the runtime environment for both packages!

您重写前缀或 DESTDIR (前缀 , DESTDIR 在它前面,但工作更可靠)在安装时的make命令行。喜欢:

Than you override prefix or DESTDIR (prefix replaces the prefix, DESTDIR is prepended to it, but works more reliably) on the make command-line when installing. Like:

~/dev/A$ ./configure ~/dev/A$ make ~/dev/A$ make install prefix=~/dev/A-install ~/dev/B$ ./configure --with-A=~/dev/A-install ~/dev/B$ make ~/dev/B$ make install prefix=~/dev/B-install

$ b b

或(这是首选的,并且是所有构建包的工具如何使用它):

or (which is preferred and is how all package-building tools use it):

~/dev/A$ ./configure ~/dev/A$ make ~/dev/A$ make install DESTDIR=~/dev/A-install ~/dev/B$ ./configure --with-A=~/dev/A-install/usr/local ~/dev/B$ make ~/dev/B$ make install prefix=~/dev/B-install

因为这样你安装到〜/ dev / A-install / $ prefix ,因此使用默认前缀〜/ dev / A-install / usr / local 。这个后面的选项的优点是,如果你重新定义一些特定的安装路径而不引用前缀(例如 - sysconfdir = / etc ), DESTDIR 仍然会在它前面,但不会受前缀的影响。

because this way you are installing to ~/dev/A-install/$prefix, so with default prefix ~/dev/A-install/usr/local. The advantage of this later option is, that if you redefine some specific installation paths without refering to prefix (say --sysconfdir=/etc), DESTDIR will still get prepended to it, while it won't be affected by prefix.

更多推荐

如何构建没有硬编码的完全依赖关系路径的共享库(.so)?

本文发布于:2023-11-25 17:06:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1630606.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   关系

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!