且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在没有硬编码的完整依赖路径的情况下构建共享库(.so)?

更新时间:2021-11-24 00:42:38

您必须使用 --prefix 值,该值将在两个包的 runtime 环境中有效!

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

比你覆盖 prefixDESTDIR (prefix 替换前缀,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

或者(这是首选,也是所有包构建工具使用它的方式):

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 仍将被添加到它,虽然它不会受到prefix的影响.

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.