编译含OpenCV 3.4.16的Android应用时arm64-v8a遇符号表错误
OpenCV 3.4.16 arm64-v8a架构编译失败问题
我开发的Android应用搭载自定义Native C++代码与OpenCV 3.4.16,因依赖4.x版本已移除的废弃模块,无法升级至OpenCV 4.x。应用在armeabi-v7a、x86、x86_64等ABI架构下编译运行均正常,但arm64-v8a架构始终编译失败,已为此困扰数周。
我已尝试相关问题的所有解决方案,其他类似问题的方案也已尝试,但均无效。
gradle.build相关配置片段
android { buildToolsVersion buildToolsVersion // tried all these NDK versions // ndkVersion = "25.2.9519653" // ndkVersion = "21.4.7075529" // ndkVersion = "23.1.7779620" ndkVersion = "22.1.7171670" // ndkVersion = "16.1.4479499" ... defaultConfig { ... externalNativeBuild { cmake { cppFlags "-std=c++11 -frtti -fexceptions -fuse-ld=lld" abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } ... } compileOptions { sourceCompatibility JavaVersion.VERSION_11 targetCompatibility JavaVersion.VERSION_11 } externalNativeBuild { cmake { path "CMakeLists.txt" version '3.18.1+' } } ...
CMakeLists.txt配置
cmake_minimum_required(VERSION 3.4.1) set (CMAKE_CXX_STANDARD 11) # OpenCV stuff include_directories(../../../OpenCV-android-sdk/sdk/native/jni/include) add_library( lib_opencv SHARED IMPORTED ) set_target_properties(lib_opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java3.so) add_library( # Sets the name of the library. native-lib # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). # Associated headers in the same location as their source # file are automatically included. src/main/cpp/native-lib.cpp src/main/cpp/MyCustomModule.cpp) find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) target_link_libraries( # Specifies the target library. native-lib # OpenCV lib lib_opencv # Links the target library to the log library # included in the NDK. ${log-lib} )
编译错误信息
仅arm64-v8a架构编译时出现如下错误:
C/C++: ld.lld: error: found local symbol '__bss_start' in global part of symbol table in file /Users/myUser/AndroidApp/android/app/src/main/jniLibs/arm64-v8a/libopencv_java3.so
OpenCV官方发布包已预编译arm64-v8a版本库,但从错误来看其符号表配置存在问题。我曾尝试在OpenCV社区查找相关信息,但始终没有进展。
请问是否有人遇到过类似问题并成功解决?
环境信息
- MacOS 13.1
- Android Studio - Electric Eel Patch 2
- Cmake 3.22.1
- 已尝试NDK版本:21、22、23、25、16(应用不支持16)
内容的提问来源于stack exchange,提问作者Raz
相关产品推荐
相关产品推荐

