object 文件和库中的符号处理

Mangling of symbol in object file and library

我为 Android (WebRTC) 构建了一个库,现在我正在尝试使用该库中的函数构建示例文件 (main.cpp)。编译步骤似乎没问题,但在 link 期间我得到了这个:

main.o:main.cpp:function main: error: undefined reference to 'webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)'

因此我检查了 main.o 中的未定义符号,我看到:

_ZN6webrtc24CreateSessionDescriptionERKSsS1_PNS_13SdpParseErrorE

在静态库中我看到:

 _ZN6webrtc24CreateSessionDescriptionERKNSt3__112basic_stringIcNS0_11char_traitsIcEENS0_9allocatorIcEEEES8_PNS_13SdpParseErrorE

我对这两个构建使用相同的 NDK,但我不确定 WebRTC 使用的 android 版本的 SDK(我正在 link 访问 platforms/android-21/arch-arm/usr/lib).

我也尝试过分解,我的 main.o 包含:

U webrtc::CreateSessionDescription(std::string const&, std::string const&, webrtc::SdpParseError*)

而图书馆包含:

T webrtc::CreateSessionDescription(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, webrtc::SdpParseError*)

知道为什么会发生这种情况以及如何避免这种情况吗?也许使用两个不同版本的字符串 header?

问题确实是该库是使用 libc++ 构建的。在 libstdc++ 上重建使 link 成功。