4

当我尝试编译测试控制台应用程序以在同一工作区上测试静态库上的某些功能时,我在二进制文件的链接阶段遇到了问题,只有当我选择使用 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)

xcode中的错误在静态库上缺少符号

当我在两个目标中选择 stdlibc++ 时,一切都编译正常并且运行正常。

标准库选项 (xcode)

我的问题是:

  1. 在静态库上使用 libc++ 有一些限制吗?
  2. 它是苹果/clang++ 链接器工具中的一个错误?
  3. 如何配置项目以将 libc++ 与我的静态库一起使用?
  4. 为什么链接器工具在静态库上找不到标准 c++ 库的符号?(任何其他依赖的库都是针对 libc++ 编译的)
  5. 我应该忘记使用 libc++ 的想法吗?

笔记:

  1. 静态库依赖于 libboost_system,我用 libc++ 和 libstdc++ 编译,结果相同
  2. 当我使用“bjam”工具运行测试时,它运行正常,也许 jam 文件选择 libstdc++ 来编译文件。
  3. 我知道更改标准库可以解决链接问题,我只想知道这是为什么。

更新:当我在静态库项目中删除对 string::empty 的引用时,依赖于 libc++ 的项目可以正常编译并运行,但它会进入无限循环。

更新 2:当我用 libstdc++ 编译整个东西时,删除 string::empty 引用没有任何效果,它运行良好。没有循环,这让我认为这是一个错误或类似的东西。

更新 3:当它编译时,这是程序无限循环的地方:在此处输入图像描述

4

2 回答 2

1

似乎您的依赖项之一 ( libtorrent) 是针对libstdc++.

检查命名空间:std::__1::basic_string。它有__1前缀,通常表示libstdc++)。

我可能错了,但我认为如果你绝对想使用这个,你需要重建你的libtorrent反对。libc++

请注意,使用stdlibc++.

于 2013-02-11T00:46:53.977 回答
0

你有没有机会用 -D_LIBCPP_INLINE_VISIBILITY="" 编译 libtorrent?

我问的原因是它std::string::empty()不在 libc++.dylib 中,因为它被标记为“always_inline”。所以它应该在使用时被内联到 libtorrent 中。

于 2013-02-11T03:33:54.643 回答