안드로이드 clang++.exe: error: linker command failed with exit code 1

안녕하세요. 개발자 드리머즈입니다.


좀 전에 안드로이드 스튜디오 버전은 3.0.1에서 3.1로 업그레이드 하고.. android sdk build tool이니 뭐니 하는 것들도 업데이트 하라고 해서 다 했습니다.

그런데 JNI 사용하는 잘 되던 OpenCV를 쓰는 프로젝트 빌드가 갑자기 안되네요.


*에러 사진



*에러 메시지

1
2
3
4
5
6
7
8
9
10
11
12
Build command failed.
Error while executing process C:\Users\xxxx\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\xxxx\AndroidStudioProjects\EyeTracker\app\.externalNativeBuild\cmake\debug\x86 --target native-lib}
[1/2] Building CXX object CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86\libnative-lib.so
FAILED: cmd.exe /C "cd . && C:\Users\xxxx\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=i686-none-linux-android --gcc-toolchain=C:/Users/xxxx/AppData/Local/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64 --sysroot=C:/Users/xxxx/AppData/Local/Android/Sdk/ndk-bundle/sysroot -fPIC -isystem C:/Users/xxxx/AppData/Local/Android/Sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=21 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security  -std=c++11 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot C:/Users/xxxx/AppData/Local/Android/Sdk/ndk-bundle/platforms/android-21/arch-x86 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -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\x86\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o  -llog C:/OpenCV-android-sdk/sdk/native/staticlibs/x86/libopencv_highgui.a C:/OpenCV-android-sdk/sdk/native/staticlibs/x86/libopencv_features2d.a C:/OpenCV-android-
(...생략...)
 
C:/Users/xxxx/AppData/Local/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/windows-x86_64/lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin\ld: error: C:/OpenCV-android-sdk/sdk/native/3rdparty/libs/x86/libippicv.a(jmp_icvippiNorm_L1_32f_C1R_as.s.o): relocation R_386_GOTOFF against preemptible symbol icv_ippJumpIndexForMergedLibs cannot be used when making a shared object
(...생략...)
 
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
cs


핵심 에러는

relocation R_386_GOTOFF against preemptible symbol icv_ippJumpIndexForMergedLibs cannot be used when making a shared object

인 것 같습니다.


다행히 스택오버플로우에 해결 방법이 있습니다.



CMakeLists.txt

1
2
3
4
5
6
7
8
9
10
11
 
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a")
 
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).
             src/main/cpp/native-lib.cpp )
cs


CMakeLists.txt의 add_library() 이전에 빨간색으로 표시한 코드를 복붙하면 빌드가 정상적으로 됩니다.


이슈가 발생한 개발환경

저의 개발 환경은 아래와 같습니다.


Android Studio 3.1.0

NDK 16.1.4479499

OpenCV 3.4.1



참고












작성자

Posted by 드리머즈

관련 글

댓글 영역