gcc -v 显示需要 -ltbb 被跳过

gcc -v shows needed -ltbb is being skipped

我有一个未定义符号的 link 错误,例如

undefined reference to `vtable for tbb::task'

我的 gcc 选项(通过 mainwin mwdip wrapper)有以下部分:

-lxerces-c -ltbb -lboost_chrono

当我使用 -v 包含详细输出时,我在详细输出中看到以下部分:

-lxerces-c -lboost_chrono

为什么详细输出会跳过一些 -l 参数?

gcc 是否试图忽略它认为不需要的库?有没有办法强制 gcc 包含它错误地认为可以跳过的所需库?

GCC 从右到左处理依赖项。您正在链接的库的未定义引用通常意味着您在链接 tbb 之后链接需要 tbb 的内容(并且链接器不会返回并重新检查 tbb 用于新需要的符号)。

一些 linker 包装器无法处理 linker 脚本,因此将 libtbb.so linker 脚本替换为 libtbb.so.2 的副本,例如

cp libtbb.so.2 libtbb.so

libtbb.so 文件是一个 ASCII 文本文件,内容如下:

INPUT (libtbb.so.2)

This is a GNU ld linker script command. Some more complex builds may not support this. For example, if you include -v in the compiler options, you can see that the mainwin gcc wrapper mwdip discards linker script command files in the verbose output list of libraries to link in.一个简单的解决方法是替换 linker 脚本输入命令文件而不是文件的副本(或 symlink)。