Android NDK链接器错误:错误:对std :: basic_string

时间:2016-07-08 20:31:36

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

我目前正在尝试构建一些需要增强的源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 ++。所以库

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'])
    }

我对应该做什么感到困惑。请告诉我如何解决此问题的方法。谢谢:))

1 个答案:

答案 0 :(得分:6)

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

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

相关问题