gpt4 book ai didi

c++11 - Android NDK 链接器错误:错误:未定义对 std::basic_string 的引用

转载 作者:行者123 更新时间:2023-12-02 23:08:02 24 4
gpt4 key购买 nike

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

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::runtime_error::runtime_error(std::string const&)'

Error:error: undefined reference to 'std::_Rb_tree_decrement(std::_Rb_tree_node_base*)'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::basic_string, std::allocator >::~basic_string()'

Error:error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator const&)'

Error:error: undefined reference to 'std::runtime_error::runtime_error(std::string const&)'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'

Error:error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base*)'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::_Rb_tree_increment(std::_Rb_tree_node_base const*)'

Error:error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::string::_Rep::_S_empty_rep_storage'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(std::string const&)'

Error:error: linker command failed with exit code 1 (use -v to see invocation)

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::string::_Rep::_M_destroy(std::allocator const&)'

Error:error: undefined reference to 'std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

Error:error: undefined reference to 'std::string::_Rep::_M_dispose(std::allocator const&)'

Error:error: undefined reference to 'std::basic_string, std::allocator >::basic_string(char const*, std::allocator const&)'

Error:error: undefined reference to 'std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)'

Error:Execution failed for task ':dummy:linkDummyArmeabiDebugSharedLibrary'.

A build operation failed. Linker failed while linking libdummy.so. See the complete log at: 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'])
}

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

最佳答案

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

如果将 STL = "c++_shared" 替换为 STL = "gnuSTL_shared"(或者 STLport_shared),那么它应该链接。或者针对 c++_shared 构建 boost。

关于c++11 - Android NDK 链接器错误:错误:未定义对 std::basic_string 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38274943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com