【问题标题】:Mangling of symbol in object file and library对象文件和库中的符号修饰
【发布时间】:2016-03-29 18:21:42
【问题描述】:

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

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,但我不确定 SDK WebRTC 使用的是哪个 android 版本(我正在链接到 platform/android-21/arch-arm/usr/ 中的库)库)。

我也尝试过 demangle 并且我的 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*)

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

【问题讨论】:

  • 您使用的是什么 C++ 库实现?请发布您的 build.gradle 和 Android.mk(如果您使用它)。
  • 是的,我怀疑 WebRTC 正在使用 libc++,而我正在使用 libstdc++。我正在使用 Qt for Android 构建,我看到命令行包含 ndk/sources/cxx-stl/gnu-libstdc++/4.8/include。我想知道有没有办法让这两者共存......
  • 你是如何构建 WebRTC 的?通过查看链接行很容易确认它正在构建的库。
  • 我没有看到构建命令,但它可能是 clang/libc++。这可能不是 Qt 所期望的。

标签: c++ stl android-ndk webrtc c++-standard-library


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-04
    • 2011-01-26
    • 1970-01-01
    • 2017-12-14
    相关资源
    最近更新 更多