交叉编译opencv4.5.3遇到如下错误:
../../lib/libopencv_world.so.4.5.3: undefined reference to `png_do_expand_palette_rgb8_neon'
../../lib/libopencv_world.so.4.5.3: undefined reference to `png_init_filter_functions_neon'
../../lib/libopencv_world.so.4.5.3: undefined reference to `png_do_expand_palette_rgba8_neon'
../../lib/libopencv_world.so.4.5.3: undefined reference to `png_riffle_palette_neon'
collect2: error: ld returned 1 exit status
apps/model-diagnostics/CMakeFiles/opencv_model_diagnostics.dir/build.make:95: recipe for target 'bin/opencv_model_diagnostics' failed
make[2]: *** [bin/opencv_model_diagnostics] Error 1
CMakeFiles/Makefile2:3183: recipe for target 'apps/model-diagnostics/CMakeFiles/opencv_model_diagnostics.dir/all' failed
make[1]: *** [apps/model-diagnostics/CMakeFiles/opencv_model_diagnostics.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
解决:
打开opencv源码目录,编辑文件 vim 3rdparty/libpng/pngpriv.h
第130行注释掉, 修改为131行
130 /* # if (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \ */
131 # if defined(PNG_ARM_NEON) && (defined(__ARM_NEON__) || defined(__ARM_NEON)) && \
132 defined(PNG_ALIGNED_MEMORY_SUPPORTED)
133 # define PNG_ARM_NEON_OPT 2
134 # else
135 # define PNG_ARM_NEON_OPT 0
136 # endif
137 #endif
1.
sudo cmake .. -D CMAKE_BUILD_TYPE=RELEASE -D
CMAKE_INSTALL_PREFIX=../install -D ENABLE_FAST_MATH=1 -D
WITH_OPENCL=ON -D WITH_IPP=OFF -D ITH_GTK=ON -D WITH_GTK3=ON -D
BUILD_SHARED_LIBS=OFF -D
CMAKE_C_COMPILER=/home/jeffrey/360/host/bin/aarch64-buildroot-linux-gnu-gcc
-D CMAKE_CXX_COMPILER=/home/jeffrey/360/host/bin/aarch64-buildroot-linux-gnu-g++
2.
sudo make -j12
3.
sudo make install