【发布时间】:2013-02-10 23:00:46
【问题描述】:
当我尝试编译测试控制台应用程序以测试同一工作区上静态库上的某些功能时,我在二进制文件的链接阶段遇到了问题,只有当我选择使用 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++ 有一些限制吗?
- 它是 apple/clang++ 链接器工具中的一个错误?
- 如何配置项目以使用 libc++ 与我的静态 图书馆?
- 为什么链接器工具找不到标准 c++ 的符号 静态库上的库?,(任何其他依赖的库都是针对 libc++ 编译的)
- 我应该忘记使用 libc++ 的想法吗?
注释:
- 静态库依赖于 libboost_system,我使用 libc++ 和 libstdc++ 编译得到相同的结果
- 当我使用“bjam”工具运行测试时,它运行正常,可能是 jam 文件选择了 libstdc++ 来编译文件。
- 我知道更改标准库可以解决链接问题,我只想知道这是为什么。
更新:当我在静态库项目中删除对 string::empty 的引用时,依赖的项目可以使用 libc++ 正常编译并运行,但它会进入无限循环。
更新 2:当我用 libstdc++ 编译整个东西时,删除 string::empty 引用没有任何效果,它运行良好。没有循环,这让我认为这是一个错误或类似的东西。
更新 3:当它编译时,这是程序无限循环的地方:
【问题讨论】:
标签: c++ xcode static-libraries clang libc++