Android OpenCV链接CXX共享库失败

时间:2019-04-19 08:05:40

标签: android c++ opencv

我有一个可以正常工作的Android Studio安装程序,当时我正在使用本机C ++代码和OpenCV编写应用程序。我停了一年的开发工作,几天前又恢复了开发。

由于Android Studio抱怨有可用的更新,所以我决定更新所有内容(Gradle,CMake,NDK ...),这是我的错误。现在构建在链接阶段停止:

Build command failed.
Error while executing process C:\Users\Marco\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\Marco\AndroidStudioProjects\MyProject\app\.externalNativeBuild\cmake\debug\x86_64 --target CppFilter}
[1/2] Building CXX object CMakeFiles/CppFilter.dir/src/main/cpp/CppFilter.cpp.o
[2/2] Linking CXX shared library ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\libCppFilter.so
FAILED: cmd.exe /C "cd . && C:\Users\Marco\AppData\Local\Android\Sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe  --target=x86_64-none-linux-android21 --gcc-toolchain=C:/Users/Marco/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/Marco/AppData/Local/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -Wa,--noexecstack -Wformat -Werror=format-security -stdlib=libc++ -O3 -O0 -fno-limit-debug-info  -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now  -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a -shared -Wl,-soname,libCppFilter.so -o ..\..\..\..\build\intermediates\cmake\debug\obj\x86_64\libCppFilter.so @CMakeFiles/CppFilter.rsp  && cd ."
D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::cerr'

D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)'

D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::put(char)'

D:/Downloads/opencv-3.3.1-android-sdk/OpenCV-android-sdk/sdk/native/libs/x86_64/libopencv_core.a(system.cpp.o):system.cpp:function cv::ipp::IPPInitSingleton::IPPInitSingleton(): error: undefined reference to 'std::ostream::flush()'

... many more of the same type ...

clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)

ninja: build stopped: subcommand failed.

我基本上遵循解释的默认设置步骤,例如:

有关导致此错误的原因的任何想法?

Android Studio的实际版本:3.4,以前的版本:2.something

1 个答案:

答案 0 :(得分:0)

显然是由于OpenCV版本(3.3.1)的编译方式与较新版本的NDK或Android SDK Build工具不兼容,例如:Why am I still getting undefined reference errors linking a static library with CMake in Android NDK?

我降级了NDK和Android SDK Build工具。现在可以了。