在 x86_64 上与 Docker 交叉编译 Raspberry Pi (aarch64) 的 OpenCV

Cross-compiling OpenCV for Raspberry Pi (aarch64) on x86_64 with Docker

提问人:Jatin Vira Robotics Engineer 提问时间:11/15/2023 最后编辑:Jatin Vira Robotics Engineer 更新时间:11/17/2023 访问量:77

问:

描述:

我正在尝试为我的 Raspberry Pi 交叉编译 OpenCV,它运行具有 aarch64 架构的 Ubuntu 20.04 LTS。我的开发机器x86_64在 Ubuntu 20.04 LTS 上运行,我正在使用 Docker 来管理构建环境。从源代码构建了多个依赖项。

版本信息:

OpenCV 版本:4.5.1
依赖项构建自: 源码:
Eigen, Boost, GRPC, Glog, Gflags, OpenBLAS, Ceres, JPEG, TIFF, WEBP, PNG, Neon, VPX, xVid, x264, FFMPEG
主机软件和 Arch: Ubuntu 20.04 LTS, x86_64
目标软件和 Arch:

Ubuntu 20.04 LTS,


Aarch64

问题:

在 OpenCV 上运行成功,输出日志添加如下:但是,调用时会失败,并显示以下日志:cmakemake

#52 601.4 [ 86%] Building CXX object modules/gapi/CMakeFiles/opencv_gapi.dir/src/backends/cpu/gcpuimgproc.cpp.o
#52 601.4 [ 86%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_main.cpp.o
#52 601.5 [ 86%] Linking CXX shared library ../../lib/libopencv_sfm.so
#52 601.9 /usr/lib/gcc-cross/aarch64-linux-gnu/9/../../../../aarch64-linux-gnu/bin/ld: ../../lib/libcorrespondence.a(nRobustViewMatching.cc.o): in function `libmv::correspondence::nRobustViewMatching::computeData(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
#52 601.9 nRobustViewMatching.cc:(.text._ZN5libmv14correspondence19nRobustViewMatching11computeDataERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE+0x54): undefined reference to `cv::imread(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, int)'
#52 601.9 collect2: error: ld returned 1 exit status
#52 601.9 make[2]: *** [modules/sfm/CMakeFiles/opencv_sfm.dir/build.make:225: lib/libopencv_sfm.so.4.5.1] Error 1
#52 601.9 make[1]: *** [CMakeFiles/Makefile2:7987: modules/sfm/CMakeFiles/opencv_sfm.dir/all] Error 2
#52 601.9 make[1]: *** Waiting for unfinished jobs....

这似乎是一个链接问题

从源头禁用 Ceres 构建可以解决问题并成功,但 Ceres 是我的构建所需的依赖项make

重现问题:

下面是指向 Dockerfile 的链接,用于运行构建:
https://github.com/JatinVira/Docker_File/blob/main/Dockerfile

这是我使用的 Cmake 工具链文件的链接:https://github.com/JatinVira/Docker_File/blob/main/rpi_aarch64.cmake

Cmake 日志:

这是构建开始前的 Cmake 摘要:

#52 36.90 -- General configuration for OpenCV 4.5.1 =====================================
#52 36.90 --   Version control:               4.5.1
#52 36.90 -- 
#52 36.90 --   Extra modules:
#52 36.96 --     Location (extra):            /root/opencv_build/opencv_contrib/modules
#52 36.96 --     Version control (extra):     4.5.1
#52 36.96 -- 
#52 36.96 --   Platform:
#52 36.96 --     Timestamp:                   2023-11-15T12:37:25Z
#52 36.96 --     Host:                        Linux 5.15.0-88-generic x86_64
#52 36.96 --     Target:                      Linux 1 aarch64
#52 36.96 --     CMake:                       3.16.3
#52 36.96 --     CMake generator:             Unix Makefiles
#52 36.96 --     CMake build tool:            /usr/bin/make
#52 36.96 --     Configuration:               Release
#52 36.96 -- 
#52 36.96 --   CPU/HW features:
#52 36.96 --     Baseline:                    NEON FP16
#52 36.96 --       required:                  NEON
#52 36.96 --       disabled:                  VFPV3
#52 36.96 -- 
#52 36.96 --   C/C++:
#52 36.96 --     Built as dynamic libs?:      YES
#52 36.96 --     C++ standard:                11
#52 36.96 --     C++ Compiler:                /usr/bin/aarch64-linux-gnu-g++  (ver 9.4.0)
#52 36.96 --     C++ flags (Release):         -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
#52 36.96 --     C++ flags (Debug):           -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
#52 36.96 --     C Compiler:                  /usr/bin/aarch64-linux-gnu-gcc
#52 36.96 --     C flags (Release):           -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
#52 36.97 --     C flags (Debug):             -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fPIC   -fsigned-char -W -Wall -Werror=return-type -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections    -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
#52 36.97 --     Linker flags (Release):      -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -Wl,--gc-sections -Wl,--as-needed  
#52 36.97 --     Linker flags (Debug):        -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now   -Wl,--gc-sections -Wl,--as-needed  
#52 36.97 --     ccache:                      YES
#52 36.97 --     Precompiled headers:         NO
#52 36.98 --     Extra dependencies:          dl m pthread rt
#52 36.98 --     3rdparty dependencies:
#52 36.98 -- 
#52 36.98 --   OpenCV modules:
#52 36.99 --     To be built:                 alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
#52 36.99 --     Disabled:                    world
#52 36.99 --     Disabled by dependency:      -
#52 36.99 --     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2 python3 viz xfeatures2d
#52 36.99 --     Applications:                tests perf_tests apps
#52 36.99 --     Documentation:               NO
#52 36.99 --     Non-free algorithms:         NO
#52 36.99 -- 
#52 36.99 --   GUI: 
#52 36.99 --     GTK+:                        NO
#52 36.99 -- 
#52 36.99 --   Media I/O: 
#52 36.99 --     ZLib:                        /usr/aarch64-linux-gnu/lib/libz.so (ver 1.2.12)
#52 36.99 --     JPEG:                        /usr/aarch64-linux-gnu/lib/libjpeg.so (ver 90)
#52 36.99 --     WEBP:                        /usr/aarch64-linux-gnu/lib/libwebp.so (ver encoder: 0x020f)
#52 36.99 --     PNG:                         /usr/aarch64-linux-gnu/lib/libpng.so (ver 1.6.37)
#52 36.99 --     TIFF:                        /usr/aarch64-linux-gnu/lib/libtiff.so (ver 42 / 4.3.0)
#52 36.99 --     JPEG 2000:                   build (ver 2.3.1)
#52 36.99 --     HDR:                         YES
#52 36.99 --     SUNRASTER:                   YES
#52 36.99 --     PXM:                         YES
#52 36.99 --     PFM:                         YES
#52 36.99 -- 
#52 36.99 --   Video I/O:
#52 36.99 --     DC1394:                      NO
#52 36.99 --     FFMPEG:                      NO
#52 36.99 --       avcodec:                   YES (58.91.100)
#52 36.99 --       avformat:                  YES (58.45.100)
#52 36.99 --       avutil:                    YES (56.51.100)
#52 36.99 --       swscale:                   YES (5.7.100)
#52 36.99 --       avresample:                NO
#52 36.99 --     GStreamer:                   NO
#52 36.99 --     v4l/v4l2:                    YES (linux/videodev2.h)
#52 36.99 -- 
#52 36.99 --   Parallel framework:            pthreads
#52 36.99 -- 
#52 36.99 --   Trace:                         YES (with Intel ITT)
#52 36.99 -- 
#52 36.99 --   Other third-party libraries:
#52 36.99 --     Lapack:                      YES (/usr/aarch64-linux-gnu/lib/libopenblas.so)
#52 36.99 --     Eigen:                       YES (ver 3.3.7)
#52 36.99 --     Custom HAL:                  YES (carotene (ver 0.0.1))
#52 36.99 --     Protobuf:                    build (3.5.1)
#52 36.99 -- 
#52 36.99 --   OpenCL:                        YES (no extra features)
#52 36.99 --     Include path:                /root/opencv_build/opencv/3rdparty/include/opencl/1.2
#52 36.99 --     Link libraries:              Dynamic load
#52 36.99 -- 
#52 36.99 --   Python (for build):            /usr/bin/python2.7
#52 36.99 -- 
#52 36.99 --   Install to:                    /usr/aarch64-linux-gnu
#52 36.99 -- -----------------------------------------------------------------
#52 36.99 -- 
#52 37.41 -- Configuring done
#52 37.98 -- Generating done
#52 38.01 -- Build files have been written to: /root/opencv_build/opencv/build

参考:

  1. https://docs.opencv.org/3.4/d0/d76/tutorial_arm_crosscompile_with_cmake.html
docker opencv raspberry-pi 交叉编译

评论

0赞 Yunus Temurlenk 11/16/2023
所以你成功安装了 OpenCV ?
0赞 Jatin Vira Robotics Engineer 11/16/2023
否,在运行 cmake 的步骤中,opencv 安装失败
0赞 Yunus Temurlenk 11/17/2023
但是我看到,cmake 输出配置并生成完成写入。似乎 cmaake 步骤过去了?
0赞 Jatin Vira Robotics Engineer 11/17/2023
我想说的是,正如你正确指出的那样,cmake已经成功了。但是制作过程失败了。我认为这是一个链接问题,当我说 cmake 步骤时......我指的是我上面添加的。生成在文件中的该步骤失败Dockerfile

答: 暂无答案