如何构建没有硬编码的完全依赖关系路径的共享库(.so)? [英] How to build a shared library (.so) without hardcoded full dependency paths?

查看:127
本文介绍了如何构建没有硬编码的完全依赖关系路径的共享库(.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)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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