使用 CMake 在 Windows 上编译适用于 Android 的 OpenCV - make 仍尝试链接“dll”文件

问题描述 投票:0回答:1

这就是我在 OpenCV 4.9.0 的根目录中设置 cmake 的方式。存储库:

cmake -DCMAKE_ANDROID_NDK=D:\...\lib\AndroidSDK\ndk\25.1.8937393 \
 -DCMAKE_SYSTEM_NAME=Android \
 -B..\OpenCV_4.9.0_builds\android_clang_ndk25 -S. \
 -DANDROID_TOOLCHAIN=clang++ \
 -DANDROID_ABI=arm64-v8a \
 -D CMAKE_BUILD_TYPE=Release \
 -D ANDROID_NATIVE_API_LEVEL=24 \
 -D WITH_CUDA=OFF \
 -D WITH_MATLAB=OFF \
 -D BUILD_ANDROID_EXAMPLES=OFF \
 -D BUILD_DOCS=OFF \
 -D BUILD_PERF_TESTS=OFF \
 -D BUILD_TESTS=OFF \
 -D ANDROID_STL=c++_shared \
 -D BUILD_SHARED_LIBS=ON

但是当我尝试转到

android_clang_ndk25
时,我可以看到它仍然使用 mingw 头文件和 mingw 链接器。

我编译:

D:\...\ndk\21.1.6352462\prebuilt\windows-x86_64\bin\make.exe install

并出现错误:

ld: error: undefined symbol: std::__once_callable
>>> referenced by C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/mutex:710
>>>               objects.a(caffe_importer.cpp.obj):(cv::dnn::dnn4_v20231225::(anonymous namespace)::CaffeImporter::extractLayerParams(google::protobuf::Message const&, cv::dnn::dnn4_v20231225::LayerParams&, bool))
>>> referenced by C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/mutex:718
>>>               objects.a(caffe_importer.cpp.obj):(cv::dnn::dnn4_v20231225::(anonymous namespace)::CaffeImporter::extractLayerParams(google::protobuf::Message const&, cv::dnn::dnn4_v20231225::LayerParams&, bool))
>>> referenced by C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/mutex:710
>>>               objects.a(caffe_importer.cpp.obj):(cv::dnn::dnn4_v20231225::(anonymous namespace)::CaffeImporter::extractLayerParams(google::protobuf::Message const&, cv::dnn::dnn4_v20231225::LayerParams&, bool))
>>> referenced 1093 more times

ld: error: undefined symbol: std::__once_call
>>> referenced by C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/mutex:712
>>>               objects.a(caffe_importer.cpp.obj):(cv::dnn::dnn4_v20231225::(anonymous namespace)::CaffeImporter::extractLayerParams(google::protobuf::Message const&, cv::dnn::dnn4_v20231225::LayerParams&, bool))
>>> referenced by C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/mutex:719
>>>               objects.a(caffe_importer.cpp.obj):(cv::dnn::dnn4_v20231225::(anonymous namespace)::CaffeImporter::extractLayerParams(google::protobuf::Message const&, cv::dnn::dnn4_v20231225::LayerParams&, bool))
>>> referenced by C:/Qt/Tools/mingw1120_64/lib/gcc/x86_64-w64-mingw32/11.2.0/include/c++/mutex:712
>>>               objects.a(caffe_importer.cpp.obj):(cv::dnn::dnn4_v20231225::(anonymous namespace)::CaffeImporter::extractLayerParams(google::protobuf::Message const&, cv::dnn::dnn4_v20231225::LayerParams&, bool))
>>> referenced 1082 more times
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [modules\dnn\CMakeFiles\opencv_dnn.dir\build.make:2858: bin/libopencv_dnn490.dll] Error 1
make[1]: *** [CMakeFiles\Makefile2:1870: modules/dnn/CMakeFiles/opencv_dnn.dir/all] Error 2
make: *** [Makefile:165: all] Error 2

值得注意的是,配置后它还说正在使用 MinGW:

-- General configuration for OpenCV 4.9.0 =====================================
--   Version control:               4.9.0
--
--   Platform:
--     Timestamp:                   2024-04-08T09:17:02Z
--     Host:                        Windows 10.0.19045 AMD64
--     CMake:                       3.25.2
--     CMake generator:             MinGW Makefiles
--     CMake build tool:            C:/Qt/Tools/mingw1120_64/bin/mingw32-make.exe
--     Configuration:               Release
android c++ opencv cmake cross-compiling
1个回答
1
投票

对我有用的最终命令如下:

cmake
 -D CMAKE_ANDROID_NDK=D:/.../lib/AndroidSDK/ndk/25.1.8937393
 -D ANDROID_SDK_ROOT=D:/.../lib/AndroidSDK
 -D CMAKE_SYSTEM_NAME=Android
 -B../OpenCV_4.9.0_builds/android_clang_ndk25
 -S.
 -D ANDROID_TOOLCHAIN=clang++
 -D CMAKE_BUILD_TYPE=Release
 -D WITH_CUDA=OFF
 -D WITH_MATLAB=OFF
 -D BUILD_ANDROID_EXAMPLES=OFF
 -D BUILD_DOCS=OFF
 -D BUILD_PERF_TESTS=OFF
 -D BUILD_TESTS=OFF
 -D ANDROID_STL=c++_shared
 -D BUILD_SHARED_LIBS=ON
 -G "Unix Makefiles"
 -DCMAKE_MAKE_PROGRAM=D:/.../lib/AndroidSDK/ndk/25.1.8937393/prebuilt/windows-x86_64/bin/make.exe
 -DCMAKE_SYSTEM_VERSION=33
 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a
 -DBUILD_JAVA=OFF
 -DBUILD_FAT_JAVA_LIB=OFF

需要系统版本来强制支持

NdkCameraManager.h
的版本,我不确定可以工作的最小版本是什么。

java 已关闭,否则当它尝试安装时,您会在 Windows 上收到此错误:

[100%] Built target opencv_java
[100%] Built target opencv_java_android_source_copy
[100%] Building OpenCV Android library project
'.' is not recognized as an internal or external command,
operable program or batch file.
make[2]: *** [modules/java/android_sdk/CMakeFiles/opencv_java_android.dir/build.make:74: opencv_android/opencv/build/outputs/aar/opencv-release.aar] Error 1
make[1]: *** [CMakeFiles/Makefile2:2353: modules/java/android_sdk/CMakeFiles/opencv_java_android.dir/all] Error 2

通过此设置,我能够编译并在出现许多其他问题后将其部署为 qt 项目。

© www.soinside.com 2019 - 2024. All rights reserved.