最近有需要使用ubuntu 树莓派4 交叉编译OPENCV,编译并不顺利,搞了好久才搞好,感谢各路前人的成果走过的路,没有他们踩过的坑,我们要想编译成功,简直是比登天还难。
坑1:
/home/li/raspi/opencv-4.1.1/3rdparty/libpng/pngstruct.h:30:10: fatal error: zlib.h: No such file or directory
#include "zlib.h"
^~~~~~~~
compilation terminated.
3rdparty/libpng/CMakeFiles/libpng.dir/build.make:62: recipe for target '3rdparty/libpng/CMakeFiles/libpng.dir/png.c.o' failed
zlib.h没有找到,打开opencv-4.1.1/3rdparty/libpng,里面确实没有这个,然后搜索一下本机上有,就把zlib.h复制到里面即可。然后把libtiff那个文件夹也复制一个,因为勾选了编译png和tiff,他们都需要这个
坑2:
in file included from /home/li/raspi/opencv-4.1.1/3rdparty/libtiff/tif_zip.c:48:0:
/home/li/raspi/opencv-4.1.1/3rdparty/libtiff/zlib.h:34:10: fatal error: zconf.h: No such file or directory
#include "zconf.h"
同上。
坑3:这个坑填了,以上两个坑可能不存在了,因为是可能这个坑导致了上面的,是我没有勾选BUILD_ZLIB,他的意思使用的zlib是x86上的,格式不认,需要勾上BUILD_ZLIB。
[ 61%] Linking CXX shared library ../../lib/libopencv_world.so
/usr/lib32/libz.so: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
modules/world/CMakeFiles/opencv_world.dir/build.make:8877: recipe for target 'lib/libopencv_world.so.4.1.1' failed
坑4:莫名其妙的东西
[ 95%] Linking CXX executable ../../bin/opencv_perf_gapi
[ 95%] Built target opencv_perf_gapi
[ 95%] Linking CXX executable ../../bin/opencv_test_core
[ 95%] Built target opencv_test_core
Makefile:162: recipe for target 'all' failed
把有关test的去掉,我去掉了BUILD_opencv_stitching,BUILD_opencv_python_tests,BUILD_opencv_ts
还有其它坑,忘记记录了