与静态库中的 std::string 相关的 C++ 未定义符号 [英] C++ Undefined symbol related to std::string in static lib
问题描述
我通过在 Linux 上使用 C++ 将一堆代码与静态库 (.a) 链接来构建共享库.我在静态库中定义了一个方法.当我使用 nm -C 打印该静态库中的符号时,它显示为:
I am building a shared lib by linking a bunch of code with a static lib (.a) on Linux in C++. I have a method defined in a static library. When I use nm -C to print the symbol in that static library is appears as:
Alembic::AbcCoreFactory::v9::IFactory::getArchive(std::string const&, Alembic::AbcCoreFactory::v9::IFactory::CoreType&)
符号未在输出 .so 文件(我正在构建的库)中定义,但是当我使用 nm -uC 列出未定义的符号时,它会打印:
The symbol is not defined in the output .so file (the library I am building), but when I list the undefined symbols using nm -uC it prints:
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&
The difference being one the first use std::string const& and the second uses std::__1::basic_string, std::__1::allocator > const&
我试图理解为什么找不到符号.两者本质上是一样的,难道不应该匹配吗?
I'm trying to understand why it is not finding the symbol. Shouldn't the two match up since they are essentially the same?
就上下文而言,我正在尝试编译 Unreal Editor 4 for linux 附带的 Alembic 导入器.我试图链接的库是 alembic 库.
For context, I am attempting to compile an Alembic Importer which come with Unreal Editor 4 for linux. The library I am attempting to link in is the alembic library.
推荐答案
您正在尝试链接针对 libc++
(clang 的标准 C++ 库)编译的代码和针对 libstdc++
编译的代码代码>(gcc 的标准 C++ 库).这不会太奏效.
You are trying to link code compiled against libc++
(the clang's standard C++ library) and code compiled against libstdc++
(the gcc's standard C++ library). This isn't going to work too well.
根据您的库检查它.
在我的系统上:
> 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 ===
在您的系统上,文件可能位于不同的位置,但结果应该相同.
On your system the files may be at different locations but the result shou;d be the same.
这篇关于与静态库中的 std::string 相关的 C++ 未定义符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!