裡面使用的是 opencv-3.4.11-android-sdk.zip (其它版本下載)
在用Android studio build時一直有問題,(當時環境是 ndk 20.x版的,連結文章是用ndk 16.x的)
...
...
...
system.cpp:(.text.unlikely._ZSt8_DestroyIPSsSsEvT_S1_RSaIT0_E.isra.88+0x18): undefined reference to `std::string::_Rep::_S_empty_rep_storage'
system.cpp:(.text.unlikely._ZSt8_DestroyIPSsSsEvT_S1_RSaIT0_E.isra.88+0x2c): undefined reference to `std::string::_Rep::_S_empty_rep_storage'
system.cpp:(.text.unlikely._ZSt8_DestroyIPSsSsEvT_S1_RSaIT0_E.isra.88+0x5c): undefined reference to `std::string::_Rep::_M_destroy(std::allocator)'
...
...
查了一陣子,應該是libc++ 或 libstdc++ 使用陣營不同的問題
NDK switched to libc++ as default STL, but OpenCV is built with gnustl.
看起來ndk 20.x版的STL是libc++, ndk 16.x版的應該是使用gnustl…吧
所以用 ndk 16.x 版的,build的過程就沒什麼問題了
(在Android 9, API_Level 28上,是跑不起來,只好用OpenCV-android-sdk_4.0.1+ndk 20.x就行了)
Tengine 人脸检测 Android版的Android/app/build.gradle
ndk {
ldLibs "log"
//声明创建指定cpu架构的so库
//如果想在模拟器运行 加上 "x86"
abiFilters 'armeabi-v7a', 'arm64-v8a'
stl "gnustl_static"
}
- Android NDK从r13起,默认使用Clang进行编译,Google会一直等到libc++(Clang的c++标准库实现)足够稳定后删掉GCC
- 詳解三大編譯器:gcc、llvm 和 clang
- libgnustl_static.a和libgnustl_static.so将逐步废弃
OpenCV-android-sdk_4.0.1+ndk 20.x
Andorid/app/build.gradle
android {
...
...
ndk {
//abiFilters 'armeabi-v7a','arm64-v8a'
abiFilters 'arm64-v8a'
stl "gunstl_static"
}
...
...
ndkVersion '20.1.5948944'
}
Andorid/app/src/main/cpp/CMakeLists.txt
...
...
...
set(OpenCV_DIR "/home/ubuntu/object_recognition/OpenCV-android-sdk_4.0.1//sdk/native/jni")
find_package(OpenCV 4.0 REQUIRED)
if(OpenCV_FOUND) (輸出 debug message :.cxx/cmake/debug/arm64-v8a/build_output.txt)
include_directories(${OpenCV_INCLUDE_DIRS})
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
message(STATUS " distribution dir: ${distribution_DIR}")
else(OpenCV_FOUND)
message(FATAL_ERROR "OpenCV library not found")
endif(OpenCV_FOUND)
include_directories(tengine/include/)
include_directories(/home/ubuntu/object_recognition/OpenCV-android-sdk_4.0.1//sdk/native/jni/include/)
add_library(tengine SHARED IMPORTED)
set_target_properties(tengine PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/libtengine-lite.so)
...
...
其中libtengine-lite.so一定要用ndk build,不要從target device摳,不然 libdl.so.2 會找不到
$ cd Tengine
$ mkdir build_android_64
$ cd build_android_64
$ cmake -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK/build/cmake/android.toolchain.cmake \
-DANDROID_ABI="arm64-v8a"\
-DANDROID_PLATFORM=android-28\
-DANDROID_STL=c++_shared
-DANDROID_ARM_NEON=ON\
-DCONFIG_ARCH_ARM64=ON\
-DANDROID_ALLOW_UNDEFINED_SYMBOLS=TRUE ..
CV_RGBA2RGB
error: use of undeclared identifier 'CV_RGBA2RGB'
改成
cv::COLOR_RGBA2RGB
ref:
1. How can I integrate OpenCV 4.0 into a pure C++ Android NDK project
2. Linking errors on Android with OpenCV 3.4.0 and NDK
3. clang: error: linker command failed with exit code 1
沒有留言:
張貼留言