静态库中与 std::string 相关的 C++ undefined symbol

标签 c++ linux symbols static-linking alembic

我正在构建共享库,方法是将一堆代码与 Linux 上的 C++ 静态库 (.a) 链接起来。我有一个在静态库中定义的方法。当我使用 nm -C 打印静态库中的符号时,显示为:

 Alembic::AbcCoreFactory::v9::IFactory::getArchive(std::string const&, Alembic::AbcCoreFactory::v9::IFactory::CoreType&)

该符号未在输出 .so 文件(我正在构建的库)中定义,但是当我使用 nm -uC 列出 undefined symbol 时,它会打印:

Alembic::AbcCoreFactory::v9::IFactory::getArchive(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, Alembic::AbcCoreFactory::v9::IFactory::CoreType&)

区别在于第一个使用 std::string const& 而第二个使用 std::__1::basic_string, std::__1::allocator > const&

我想了解为什么找不到符号。两者本质上是一样的,难道不应该匹配吗?

对于上下文,我正在尝试编译一个 Alembic Importer,它随 Unreal Editor 4 for linux 一起提供。我试图链接的库是 alembic 库。

最佳答案

您正在尝试链接根据 libc++(clang 的标准 C++ 库)编译的代码和根据 libstdc++(gcc 的标准 C++ 库)编译的代码。这不会太有效。

对照您的图书馆检查它。

在我的系统上:

> nm -DC /usr/lib64/libc++_shared.so | grep 'std::__1'
  === lots of output ===
> nm -DC /usr/lib64/libc++_shared.so | grep 'std::basic'
  === nothing ===
> nm -DC /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/libstdc++.so.6 | grep 'std::__1'
  === nothing ===
> nm -DC /usr/lib/gcc/x86_64-pc-linux-gnu/6.2.0/libstdc++.so.6 | grep 'std::basic'
  === lots of output ===

在您的系统上,文件可能位于不同的位置,但结果应该是相同的。

关于静态库中与 std::string 相关的 C++ undefined symbol ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42323444/

相关文章:

c - 使用 DT_FILTER 从 DSO 隐藏符号

c++ - 向 QGridLayout 添加太多的 Widget

c++ - 使用 NULL 值初始化指向类的指针

c++ - 用线程池替换许多 std::async 调用

c++ - 用不同版本编译的相同代码提供不同的结果

与共享库的 C++ 静态库链接。编译会好吗?

linux - 链接共享库 g++ 时出现奇怪的符号

c++ - 我如何掌握纯 OOD 的概念?

linux - 检查 git 提交是否是一天的第一天的脚本

c++ - 将数学符号存储到字符串C++中