При попытке создать этот пример проекта https://github.com/caffe2/AICamera/tree/master/app/src/main/cpp Я получаю сотни error: undefined reference
s. Вот первые несколько строк вывода:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process /home/aidan/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {--build /home/aidan/AndroidStudioProjects/AICamera/app/.externalNativeBuild/cmake/debug/armeabi-v7a --target native-lib}
[1/1] Linking CXX shared library ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so
FAILED: : && /home/aidan/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=armv7-none-linux-androideabi --gcc-toolchain=/home/aidan/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/aidan/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem /home/aidan/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -D__ANDROID_API__=22 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -frtti -fexceptions -std=c++11 -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -nostdlib++ --sysroot /home/aidan/Android/Sdk/ndk-bundle/platforms/android-22/arch-arm -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--fix-cortex-a8 -Wl,--exclude-libs,libunwind.a -L/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-lib.so -o ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -Wl,--whole-archive ../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a -Wl,--no-whole-archive ../../../../src/main/jniLibs/armeabi-v7a/libCAFFE2_NNPACK.a ../../../../src/main/jniLibs/armeabi-v7a/libCAFFE2_PTHREADPOOL.a ../../../../src/main/jniLibs/armeabi-v7a/libglog.so ../../../../src/main/jniLibs/armeabi-v7a/libprotobuf.a libcpufeatures.a /home/aidan/Android/Sdk/ndk-bundle/platforms/android-22/arch-arm/usr/lib/liblog.so /home/aidan/Android/Sdk/ndk-bundle/platforms/android-22/arch-arm/usr/lib/libandroid.so -ldl -latomic -lm "/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++_static.a" "/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libc++abi.a" "/home/aidan/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/libunwind.a" "-ldl" && :
../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a(nnpack_ops.cc.o):nnpack_ops.cc:function std::_Sp_counted_deleter<void*, void (*)(void*), std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_get_deleter(std::type_info const&): error: undefined reference to 'std::type_info::operator==(std::type_info const&) const'
../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a(nnpack_ops.cc.o):nnpack_ops.cc:function std::_Sp_counted_deleter<void*, caffe2::Tensor<caffe2::CPUContext>::raw_mutable_data(caffe2::TypeMeta const&)::{lambda(void*)#1}, std::allocator<void>, (__gnu_cxx::_Lock_policy)2>::_M_get_deleter(std::type_info const&): error: undefined reference to 'std::type_info::operator==(std::type_info const&) const'
../../../../src/main/jniLibs/armeabi-v7a/libCaffe2_CPU.a(nnpack_ops.cc.o):nnpack_ops.cc:function void caffe2::TypeMeta::_CopyNotAllowed<caffe2::Tensor<caffe2::CPUContext> >(void const*, void*, unsigned int): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int)'
... + 100s of similar lines, all with undefined references
Это моя первая попытка Android NDK, поэтому я новичок в этом и имею ограниченный опыт создания C ++. Из того, что я вижу, это похоже на ошибку компоновки, так как не может найти std
, Из-за моего ограниченного опыта, я не могу понять, как я мог бы решить эту проблему.
Вот мой CMakeLists.txt
файл
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_CPU.a
)
add_library(
thread_pool
STATIC
IMPORTED
)
set_target_properties(
thread_pool
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libCAFFE2_PTHREADPOOL.a
)
add_library(
glog
SHARED
IMPORTED
)
set_target_properties(
glog
PROPERTIES IMPORTED_LOCATION
${CMAKE_CURRENT_LIST_DIR}/src/main/jniLibs/${ANDROID_ABI}/libglog.so
)
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}/libCAFFE2_NNPACK.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
glog
protobuf
cpufeatures
${log-lib}
${android-lib})
caffe2 / AICamera нативные библиотеки были подготовлены для libgnustl_shared.so (увидеть jniLibs), но ваши проекты использует Libc ++ _ static.a вместо. Вы должны указать
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=gnustl_shared"}
}
в вашем build.gradle, или восстановить libCaffe2_ библиотеки.
Других решений пока нет …