前言
本文为记载常见过错文章,并非技术共享文。
问题如下:
CmakeList中链接libopencv.so。编译时报错。
详细报错代码:
> Task :library-native:buildCMakeDebug[arm64-v8a] FAILED
C/C++: ninja: Entering directory `G:\AndroidStudioProjects\HelloAndroid\library-native\.cxx\Debug\1t442u5r\arm64-v8a'
C/C++: ld: error: found local symbol '_edata' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: ld: error: found local symbol '__end__' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: ld: error: found local symbol '__bss_end__' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: ld: error: found local symbol '_bss_end__' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: ld: error: found local symbol '__bss_start__' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: ld: error: found local symbol '_end' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: ld: error: found local symbol '__bss_start' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
C/C++: clang++: error: linker command failed with exit code 1 (use -v to see invocation)
C/C++: ld: error: found local symbol '__bss_start' in global part of symbol table in file G:/AndroidStudioProjects/HelloAndroid/library-native/libs/arm64-v8a/libopencv_java3.so
解决办法
网上看到了很多解决办法,都来源于这篇文章:local symbol ‘__bss_start’ in global part of symbol table” only in Android NDK aarch64 build]
最后文章中有人提到了,更换ndk版别。经测试,更换NDK到21.4.xxx版别及以下都可以编译。如下图:
注意事项
该问题仅存在于arm64-v8a中,armeabi-v7a中并无问题。