遇到 ld.lld: error: found local symbol ‘__bss_start‘ in global part of symbol table in file 错误

在用AndroidStudio开发APP时,因重新拉取git仓库代码,导致以下错误:

[164/164] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\arm64-v8a\libailiving.so
FAILED: cmd.exe /C "cd . && C:\Users\LENOVO\AppData\Local\Android\Sdk\ndk\22.1.7171670\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=aarch64-none-linux-android24 --gcc-toolchain=C:/Users/LENOVO/AppData/Local/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/LENOVO/AppData/Local/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security  -O3 -fexceptions -fsigned-char -frtti -std=c++14 -Wformat -fuse-ld=lld -std=gnu++11 -O2 -DNDEBUG  -s -O3 -Wall  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libgcc_real.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id=sha1 -Wl,--no-rosegment -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -shared -Wl,   .............. ../../../../src/main/jniLibs/arm64-v8a/libvulkan.so -llog -latomic -lm && cd ."
ld.lld: error: found local symbol '_edata' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
ld.lld: error: found local symbol '__end__' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
ld.lld: error: found local symbol '__bss_end__' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
ld.lld: error: found local symbol '_bss_end__' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
ld.lld: error: found local symbol '__bss_start__' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
ld.lld: error: found local symbol '_end' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
ld.lld: error: found local symbol '__bss_start' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

> Task :app:externalNativeBuildDebug FAILED
ld.lld: error: found local symbol '__bss_start' in global part of symbol table in file ../../../../src/main/jniLibs/arm64-v8a/libopencv_java3.so

上面错误明显是链接时  __bss_start 等重复了。网上有说在CMake加  -fuse-ld=gold 或者 -fuse-ld=lld 编译项的。(参考 "local symbol '__bss_start' in global part of symbol table" only in Android NDK aarch64 build - Stack Overflow)

其实都没有用,归根结底还是NDK版本不同导致的,因为libopencv_java3.so库文件是在官网下载的,不知道但是是用什么方式编译生成的。想想之前的代码一点问题都没有,为什么重新拉取代码后就出问题呢?应该还是编译环境不同导致的。

我这里用的是NDK版本是22.1.7171670,找回之前的项目目录查看NDK版本发现是21.1.6352462。立刻更换NDK版本,就能编译通过了。

看来,用第三方编译好了的库文件还有版本匹配的风险。

你可能感兴趣的:(Android,多媒体,Android开发)