且构网

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

使用相对路径构建的 boost 库

更新时间:2023-11-16 18:02:28

如果您运行 objdump -p libboost_thread.so,您会发现 libboost_system.so 的 NEEDED 条目包含一个(相对) 小路.根据 ELF 规范,NEEDED 条目应仅包含所需库的名称,因此链接器或 QCC 中似乎存在错误.

If you run objdump -p libboost_thread.so, you'll find that the NEEDED entry for libboost_system.so contains a (relative) path. According to the ELF specification, the NEEDED entry should contain only the name of the needed library, so there seems to be a bug in the linker or in QCC.

因为如果这样,系统将无法在运行时找到该文件,除非当前目录与链接发生时的目录相同.

Because if this, the system won't be able to find the file at run-time unless the current directory is the same as it was when linking took place.

最简单的解决方法是静态链接到 libboost_thread.a.

The simplest work-around is to link statically to libboost_thread.a.

我自己使用的另一种解决方法是围绕 QCC 创建一个包装器,用于转换命令行,以便将依赖项指定为 -Wl,-L ;-Wl,-l 而不是 /lib.so 这也需要对 Boost 构建系统进行更改,以便它不会附加库文件名末尾的版本号.

Another work-around that I've used myself is to create a wrapper around QCC that transforms the command line so that dependencies are given as -Wl,-L <path> -Wl,-l <name> instead of <path>/lib<name>.so This also requires a change to the Boost build system so that it doesn't append the version number to the end of library file names.