编译流程:

参考:https://juejin.cn/post/6844903793650302989

1.构建独立的交叉编译环境(不知道有啥用,也没有去实验缺少这一步有什么问题)

../android-ndk-r16b/build/tools/make-standalone-toolchain.sh\
--toolchain=arm-linux-androideabi-4.9\ #编译工具名字
--platform=android-21\ android api的级别
--install-dir=../android-toolchain-r16b/android-armv7\ 生成工具链的安装目录
--arch=arm\ #编译器版本
--force #使用该选项会先移除安装目录下已经存在的工具 

2.编译opencv动态库

export ANDROID_NDK=/home/nn/Project/android-ndk-r14b (这一步非常重要,一定要export,我报错就是少了这一步)

cmake -DCMAKE_TOOLCHAIN_FILE=../platforms/android/android.toolchain.cmake \
-DCMAKE_ANDROID_NDK=/home/nn/Project/android-ndk-r14b \
-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 \
-DCMAKE_INSTALL_PREFIX=/youpath/opencv/install ..

3.make -j16 && make install (具体看你电脑内核数啦,我是16核的,可以跑32线程,这里只跑了16个,飞快...)

具体错误:

/home/wushengqi/ai/opencv-3.4.6/3rdparty/libtiff/tif_stream.cxx:29:20: fatal error: iostream: No such file or directory
 #include <iostream>
                    ^
compilation terminated.
3rdparty/libtiff/CMakeFiles/libtiff.dir/build.make:1022: recipe for target '3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_stream.cxx.o' failed
make[2]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/tif_stream.cxx.o] Error 1
CMakeFiles/Makefile2:422: recipe for target '3rdparty/libtiff/CMakeFiles/libtiff.dir/all' failed
make[1]: *** [3rdparty/libtiff/CMakeFiles/libtiff.dir/all] Error 2
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2

一开始网上说是anaconda的问题,但是我切换到一个纯净的Ubuntu环境还是不行。

后面灵机一动,将我构建文件夹下面cmake产生的信息删除。然后重新执行上面2、3步骤,OK了。

 

Logo

鸿蒙生态一站式服务平台。

更多推荐