Android 对大量caffe2库的未定义引用

Android 对大量caffe2库的未定义引用,android,cmake,caffe2,Android,Cmake,Caffe2,我遇到的错误与此处描述的相同: 但是,在使用解决方案后,我们会得到另一种类型的错误: /home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)' /home/augustinas/Android/Sdk/ndk-bundle/s

我遇到的错误与此处描述的相同:

但是,在使用解决方案后,我们会得到另一种类型的错误:

/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:302: error: undefined reference to 'std::__ndk1::locale::~locale()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:302: error: undefined reference to 'std::__ndk1::locale::~locale()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:683: error: undefined reference to 'std::__ndk1::ios_base::~ios_base()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:683: error: undefined reference to 'std::__ndk1::ios_base::~ios_base()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:302: error: undefined reference to 'std::__ndk1::locale::~locale()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:302: error: undefined reference to 'std::__ndk1::locale::~locale()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:683: error: undefined reference to 'std::__ndk1::ios_base::~ios_base()'
../../../../src/main/jniLibs/armeabi-v7a/libcaffe2.a(Device.cpp.o):Device.cpp:function virtual thunk to std::__ndk1::basic_ostringstream<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> >::~basic_ostringstream(): error: undefined reference to 'std::__ndk1::ios_base::~ios_base()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:529: error: undefined reference to 'std::__ndk1::ios_base::clear(unsigned int)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:529: error: undefined reference to 'std::__ndk1::ios_base::clear(unsigned int)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:955: error: undefined reference to 'std::__ndk1::ios_base::__set_badbit_and_consider_rethrow()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:461: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/__locale:212: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:756: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/__locale:212: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:529: error: undefined reference to 'std::__ndk1::ios_base::clear(unsigned int)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:472: error: undefined reference to 'std::__ndk1::ios_base::__set_badbit_and_consider_rethrow()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:461: error: undefined reference to 'std::__ndk1::num_put<char, std::__ndk1::ostreambuf_iterator<char, std::__ndk1::char_traits<char> > >::id'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:461: error: undefined reference to 'std::__ndk1::ctype<char>::id'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/istream:321: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/__locale:212: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:529: error: undefined reference to 'std::__ndk1::ios_base::clear(unsigned int)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:193: error: undefined reference to 'std::__ndk1::ctype<char>::id'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/istream:713: error: undefined reference to 'std::__ndk1::ios_base::getloc() const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/__locale:212: error: undefined reference to 'std::__ndk1::locale::use_facet(std::__ndk1::locale::id&) const'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/istream:732: error: undefined reference to 'std::__ndk1::ios_base::__set_badbit_and_consider_rethrow()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/istream:730: error: undefined reference to 'std::__ndk1::num_get<char, std::__ndk1::istreambuf_iterator<char, std::__ndk1::char_traits<char> > >::id'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:739: error: undefined reference to 'std::__ndk1::ios_base::__set_badbit_and_consider_rethrow()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ostream:737: error: undefined reference to 'std::__ndk1::ctype<char>::id'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:690: error: undefined reference to 'std::__ndk1::ios_base::init(void*)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:311: error: undefined reference to 'std::__ndk1::locale::locale()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:690: error: undefined reference to 'std::__ndk1::ios_base::init(void*)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:311: error: undefined reference to 'std::__ndk1::locale::locale()'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/stdexcept:146: error: undefined reference to 'std::logic_error::logic_error(char const*)'
../../../../src/main/jniLibs/armeabi-v7a/libcaffe2.a(Device.cpp.o):Device.cpp:typeinfo for std::__ndk1::basic_ios<char, std::__ndk1::char_traits<char> >: error: undefined reference to 'typeinfo for std::__ndk1::ios_base'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/stdexcept:136: error: undefined reference to 'std::logic_error::logic_error(char const*)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/ios:690: error: undefined reference to 'std::__ndk1::ios_base::init(void*)'
/home/augustinas/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include/streambuf:311: error: undefined reference to 'std::__ndk1::locale::locale()'

似乎导入的
caffe2
目标缺少其libc++依赖项。您可能需要使用
set\u target\u properties
来设置该位置。我们使用的是android studio。你能澄清一下我们应该使用什么命令以及应该链接什么吗?我想是你写的
CMakeLists.txt
;您应该使用
set_target_属性(导入的caffe2属性_LINK_依赖的_库[libc++.so或.a的路径]
。基本上是构建的
/home/augustinas/Android/Sdk/ndk bundle/sources/cxx stl/llvm libc++/
库的路径,无论它放在哪里。不。错误仍然在这里。你还有什么建议吗?完整输出:你似乎仍然在混合
libgnustl\u共享。因此
libc++\u static.a
。你的一些静态库使用其中一个或另一个进行重新构建,这就是链接步骤失败的原因。我在CMake调用的任何地方都看不到此选项
-DANDROID\u STL=gnustl\u shared
(由post建议);您是否清理了CMake缓存?
cmake_minimum_required(VERSION 3.4.1)

add_library(
             native-lib
             SHARED
             src/main/cpp/native-lib.cpp
             )
find_library(
          android-lib
          android
          )

include(AndroidNdkModules)
android_ndk_import_module_cpufeatures()

add_library(
    caffe2
    STATIC
    IMPORTED
    )
set_target_properties(
    caffe2
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libcaffe2.a
    )
add_library(
    thread_pool
    STATIC
    IMPORTED
    )
set_target_properties(
    thread_pool
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libpthreadpool.a
    )
add_library(
    clog
    SHARED
    IMPORTED
    )
set_target_properties(
    clog
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libclog.a
    )

add_library(
    protobuf
    SHARED
    IMPORTED
    )
set_target_properties(
    protobuf
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libprotobuf.a
    )

add_library(
    NNPACK
    STATIC
    IMPORTED
    )
set_target_properties(
    NNPACK
    PROPERTIES IMPORTED_LOCATION
    ${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libnnpack.a
    )

include_directories( src/main/cpp )

find_library(
     log-lib
     log
     )

target_link_libraries(
                       native-lib
                       -Wl,--whole-archive
                       caffe2
                       -Wl,--no-whole-archive
                       NNPACK
                       thread_pool
                       clog
                       protobuf
                       cpufeatures
                       ${log-lib}
                       ${android-lib})