当我尝试编译测试控制台应用程序以在同一工作区上测试静态库上的某些功能时,我在二进制文件的链接阶段遇到了问题,只有当我选择使用 libc++ 标准库时才会发生这种情况。
缺少符号错误如下:
Undefined symbols for architecture x86_64:
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::empty() const", referenced from:
libtorrent::torrent::replace_trackers(std::__1::vector<libtorrent::announce_entry, std::__1::allocator<libtorrent::announce_entry> > const&) in libLibOFFTorrent-xcode.a(torrent.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
当我在两个目标中选择 stdlibc++ 时,一切都编译正常并且运行正常。
我的问题是:
- 在静态库上使用 libc++ 有一些限制吗?
- 它是苹果/clang++ 链接器工具中的一个错误?
- 如何配置项目以将 libc++ 与我的静态库一起使用?
- 为什么链接器工具在静态库上找不到标准 c++ 库的符号?(任何其他依赖的库都是针对 libc++ 编译的)
- 我应该忘记使用 libc++ 的想法吗?
笔记:
- 静态库依赖于 libboost_system,我用 libc++ 和 libstdc++ 编译,结果相同
- 当我使用“bjam”工具运行测试时,它运行正常,也许 jam 文件选择 libstdc++ 来编译文件。
- 我知道更改标准库可以解决链接问题,我只想知道这是为什么。
更新:当我在静态库项目中删除对 string::empty 的引用时,依赖于 libc++ 的项目可以正常编译并运行,但它会进入无限循环。
更新 2:当我用 libstdc++ 编译整个东西时,删除 string::empty 引用没有任何效果,它运行良好。没有循环,这让我认为这是一个错误或类似的东西。
更新 3:当它编译时,这是程序无限循环的地方: