【问题标题】:Android NDK linker Error:error: undefined reference to std::basic_stringAndroid NDK 链接器错误:错误:未定义对 std::basic_string 的引用
【发布时间】:2016-11-11 12:16:57
【问题描述】:

我目前正在尝试构建一些需要 boost 的源 c++ 文件的静态库。我一直在关注hello-libs 示例,并已成功链接 boost 静态文件依赖项,如示例示例中所做的那样。现在说,在构建模块期间,我得到了这些错误:

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

错误:错误:未定义对 'std::runtime_error::runtime_error(std::string const&)' 的引用

错误:错误:未定义对“std::_Rb_tree_decrement(std::_Rb_tree_node_base*)”的引用

错误:错误:未定义对“std::string::_Rep::_S_empty_rep_storage”的引用

错误:错误:未定义引用 'std::basic_string, std::allocator >::~basic_string()'

错误:错误:未定义引用 'std::string::_Rep::_M_dispose(std::allocator const&)'

错误:错误:未定义对 'std::runtime_error::runtime_error(std::string const&)' 的引用

错误:错误:未定义引用 'std::string::_Rep::_M_destroy(std::allocator const&)'

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(std::string const&)'

错误:错误:未定义对“std::_Rb_tree_increment(std::_Rb_tree_node_base*)”的引用

错误:错误:未定义对“std::string::_Rep::_S_empty_rep_storage”的引用

错误:错误:未定义引用 'std::string::_Rep::_M_destroy(std::allocator const&)'

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(std::string const&)'

错误:错误:未定义引用 'std::string::_Rep::_M_destroy(std::allocator const&)'

错误:错误:未定义对“std::_Rb_tree_increment(std::_Rb_tree_node_base const*)”的引用

错误:错误:未定义引用 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

错误:错误:未定义对“std::string::_Rep::_S_empty_rep_storage”的引用

错误:错误:未定义对“std::string::_Rep::_S_empty_rep_storage”的引用

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(std::string const&)'

错误:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

错误:错误:未定义引用 'std::string::_Rep::_M_destroy(std::allocator const&)'

错误:错误:未定义引用 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

错误:错误:未定义引用 'std::string::_Rep::_M_dispose(std::allocator const&)'

错误:错误:未定义引用 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

错误:错误:未定义引用 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

错误:任务“:dummy:linkDummyArmeabiDebugSharedLibrary”执行失败。

构建操作失败。 链接器在链接 libdummy.so 时失败。 查看完整日志:file:///home/cran-cg/Downloads/Hello-libs-boost/name/build/tmp/linkDummyArmeabiDebugSharedLibrary/output.txt

我一直在尝试解决这个问题,并在 stackoverflow 本身上遇到了许多解决方案,建议我应该修改我的链接器路径并包含 libc++.so 库

ndk{
        moduleName = 'p2psp'
        stl = "c++_shared"
       // ldLibs.addAll('-L'+ file("/home/cran-cg/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi").absolutePath)
        ldLibs.addAll(['android', 'log','atomic'])/*"${NDK_ROOT}/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi",'gnustl_static'*/
        toolchain = "clang"
        cppFlags.add("-std=c++11")
        cppFlags.add('-frtti')
        cppFlags.add('-fexceptions')
        cppFlags.addAll('-I' + file("/home/cran-cg/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libcxx/include").absolutePath ,'-DANDROID', ' -DANDROID_NDK', '-DAWS_CUSTOM_MEMORY_MANAGEMENT', '-fPIC', '-fexceptions')
        //cppFlags.add("-I${lib_distribution_root}/boost/include".toString())
        //cppFlags.add("-I${file("src/main/jni/inc")}".toString())

        abiFilters.addAll(['armeabi'])//, 'armeabi-v7a', 'x86'])
    }

我对应该做什么感到困惑。请建议我如何解决此问题。谢谢:))

【问题讨论】:

    标签: c++11 android-ndk android-gradle-plugin build.gradle ndk-build


    【解决方案1】:

    看起来您的 boost 库是针对 gnustl(或者可能是 stlport)构建的,而您使用的是 libc++。您不能混合和匹配 STL,因为它们不兼容 ABI。

    如果您将stl = "c++_shared" 替换为stl = "gnustl_shared"(或者可能是stlport_shared,那么它应该链接。或者针对c++_shared 构建提升。

    【讨论】:

    • 是的,这就是问题所在。解决了它:)) 但是使用 gnustl_shared 我得到了对“to_chars”的未定义引用。最后我不得不注释掉所有的跟踪消息并且它起作用了。
    • 嗨@cRAN我遇到了类似的问题,未定义对to_chars的引用;您能否详细说明“注释掉所有跟踪消息”的含义?谢谢!
    • TRACE("Waiting for the player at (" << endpoint.address().to_string() << "," << std::to_string(endpoint.port()) << ")"); 这样的东西
    猜你喜欢
    • 1970-01-01
    • 2012-03-02
    • 2013-05-07
    • 2019-01-16
    • 2018-06-02
    • 2011-05-01
    • 1970-01-01
    • 2010-12-25
    • 1970-01-01
    相关资源
    最近更新 更多