nihui的opencv-mobile要求Android sdk大于24,且编译时关闭了rtti,所以需要自己手动编译一个 一、编译环境 系统:Ubuntu ndk版本:android-ndk-r21d 修改环境变量
sudo vim etc/profile
#etc/profile末尾
export NDKROOT=/path/to/android-ndk-r21d
export PATH=$NDKROOT:$PATH
#启用环境变量
source profile
cmake:cmake version 3.13.3 ant安装:
sudo apt-get install ant
#配置/etc/profile
export ANT_HOME=/path/to/ant
export PATH=$ANT_HOME/bin:$PATH
#启用环境变量
source profile
二、编译 下载opencv-mobile和opencv-4.5.4
git clone https:
cd opencv-mobile
wget -q https:
unzip -q opencv-4.5.4.zip
cd opencv-4.5.4
mkdir build
cd build
参考https://blog.csdn.net/yang332233/article/details/105503358,开始编译armeabi-v7a
cmake -DCMAKE_TOOLCHAIN_FILE=/home/image-pc/software/android-ndk/android-ndk-r21d/build/cmake/android.toolchain.cmake -DCMAKE_ANDROID_NDK=/home/image-pc/software/android-ndk/android-ndk-r21d -DANDROID_NATIVE_API_LEVEL=21 -DBUILD_ANDROID_PROJECTS=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_JAVA=OFF -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a `cat ../../opencv4_cmake_options.txt`
-DBUILD_opencv_world=OFF -DCMAKE_INSTALL_PREFIX=../install ..
make -j8
make install
能够正常生成,结果在install文件夹下
但是设置了arm64-v8a,不能生效
cmake -DCMAKE_TOOLCHAIN_FILE=/home/image-pc/software/android-ndk/android-ndk-r21d/build/cmake/android.toolchain.cmake -DCMAKE_ANDROID_NDK=/home/image-pc/software/android-ndk/android-ndk-r21d -DANDROID_NATIVE_API_LEVEL=21 -DBUILD_ANDROID_PROJECTS=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DCMAKE_BUILD_TYPE=Release -DBUILD_JAVA=OFF -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a `cat ../../opencv4_cmake_options.txt`
llc-DBUILD_opencv_world=OFF -DCMAKE_INSTALL_PREFIX=../install ..
生成的还是armeabi-v7a框架下的 强行修改/home/image-pc/software/android-ndk/android-ndk-r21d/build/cmake/android.toolchain.cmake,增加SET(ANDROID_ABI “arm64-v8a”),报错。
-- Check for working CXX compiler: /home/image-pc/software/android-ndk/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++
-- Check for working CXX compiler: /home/image-pc/software/android-ndk/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ -- broken
CMake Error at /opt/cmake-3.13.3/share/cmake-3.13/Modules/CMakeTestCXXCompiler.cmake:45 (message):
The C++ compiler
"/home/image-pc/software/android-ndk/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: /home/image-pc/software/opencv/opencv-mobile/opencv-4.5.4/build/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_785c9/fast"
/usr/bin/make -f CMakeFiles/cmTC_785c9.dir/build.make CMakeFiles/cmTC_785c9.dir/build
make[1]: 进入目录“/home/image-pc/software/opencv/opencv-mobile/opencv-4.5.4/build/CMakeFiles/CMakeTmp”
Building CXX object CMakeFiles/cmTC_785c9.dir/testCXXCompiler.cxx.o
/home/image-pc/software/android-ndk/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++ --target=aarch64-none-linux-android21 --gcc-toolchain=/home/image-pc/software/android-ndk/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64 --sysroot=/home/image-pc/software/android-ndk/android-ndk-r21d/toolchains/llvm/prebuilt/linux-x86_64/sysroot -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -march=armv7-a -mthumb -Wformat -Werror=format-security -fPIE -o CMakeFiles/cmTC_785c9.dir/testCXXCompiler.cxx.o -c /home/image-pc/software/opencv/opencv-mobile/opencv-4.5.4/build/CMakeFiles/CMakeTmp/testCXXCompiler.cxx
clang++: error: the clang compiler does not support '-march=armv7-a'
CMakeFiles/cmTC_785c9.dir/build.make:65: recipe for target 'CMakeFiles/cmTC_785c9.dir/testCXXCompiler.cxx.o' failed
make[1]: *** [CMakeFiles/cmTC_785c9.dir/testCXXCompiler.cxx.o] Error 1
make[1]: 离开目录“/home/image-pc/software/opencv/opencv-mobile/opencv-4.5.4/build/CMakeFiles/CMakeTmp”
Makefile:121: recipe for target 'cmTC_785c9/fast' failed
make: *** [cmTC_785c9/fast] Error 2
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:107 (enable_language)
-- Configuring incomplete, errors occurred!
See also "/home/image-pc/software/opencv/opencv-mobile/opencv-4.5.4/build/CMakeFiles/CMakeOutput.log".
See also "/home/image-pc/software/opencv/opencv-mobile/opencv-4.5.4/build/CMakeFiles/CMakeError.log".
数次尝试,无果
参考https://www.jianshu.com/p/45fb1dc6a041,对比命令,发现DCMAKE_ANDROID_ARCH_ABI这个编译选项没有生效,修改为DANDROID_ABI,可以正常编译得到结果
|