C++ Undefined symbol related to std::string in static lib

独自空忆成欢 提交于 2019-12-23 22:43:35

问题


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&)

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&)

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?

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.


回答1:


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.

Check it against your libraries.

On my system:

> 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.



来源:https://stackoverflow.com/questions/42323444/c-undefined-symbol-related-to-stdstring-in-static-lib

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!