问题描述
我想达到什么目的?
我正在尝试按照以下 2 个指南为 ARM(用于 RaspBerry Pi 4 - RaspBerry OS 桌面)交叉编译 OpenCV 4.5.2:
- Cross compilation for ARM based Linux systems
- Cross compiling OpenCV 4 for Raspberry Pi and BeagleBone Black
我正在经历什么?
但是我可以看到很多关于由于某些 pkg-config 问题而无法找到某些库的 cmake 升温:
#19 39.61 -- Looking for dlerror in dl - found
#19 39.65 -- ADE: Download: v0.1.1f.zip
#19 40.28 -- OpenCV Python: during development append to PYTHONPATH: /opencv-4.5.2/platforms/linux/build/python_loader
#19 40.29 -- Found PkgConfig: /usr/bin/pkg-config (found version "0.29")
#19 40.30 -- Checking for modules 'libavcodec;libavformat;libavutil;libswscale'
#19 40.33 -- Found libavcodec,version 58.35.100
#19 40.34 -- Found libavformat,version 58.20.100
#19 40.36 -- Found libavutil,version 56.22.100
#19 40.38 -- Found libswscale,version 5.3.100
#19 40.43 CMake Warning at cmake/OpenCVUtils.cmake:882 (message):
#19 40.43 ocv_check_modules(FFMPEG): can't find library 'avcodec'. Specify
#19 40.43 'pkgcfg_lib_FFMPEG_avcodec' manually
#19 40.43 Call Stack (most recent call first):
#19 40.43 modules/videoio/cmake/detect_ffmpeg.cmake:30 (ocv_check_modules)
#19 40.43 modules/videoio/cmake/init.cmake:7 (include)
#19 40.43 modules/videoio/cmake/init.cmake:18 (add_backend)
#19 40.43 cmake/OpenCVModule.cmake:298 (include)
#19 40.43 cmake/OpenCVModule.cmake:361 (_add_modules_1)
#19 40.43 modules/CMakeLists.txt:7 (ocv_glob_modules)
#19 40.43
#19 40.43
#19 40.43 CMake Warning at cmake/OpenCVUtils.cmake:882 (message):
#19 40.43 ocv_check_modules(FFMPEG): can't find library 'avformat'. Specify
#19 40.43 'pkgcfg_lib_FFMPEG_avformat' manually
#19 40.43 Call Stack (most recent call first):
#19 40.43 modules/videoio/cmake/detect_ffmpeg.cmake:30 (ocv_check_modules)
#19 40.43 modules/videoio/cmake/init.cmake:7 (include)
#19 40.43 modules/videoio/cmake/init.cmake:18 (add_backend)
#19 40.43 cmake/OpenCVModule.cmake:298 (include)
#19 40.43 cmake/OpenCVModule.cmake:361 (_add_modules_1)
#19 40.43 modules/CMakeLists.txt:7 (ocv_glob_modules)
基本上,我看到我自己安装的所有库/依赖项都有类似的警告。
我在做什么?
我在基于 debian:buster(最新)amd64 的 docker 容器中运行编译。
而我所做的是:
- 安装开发环境
GNU_HOST=arm-linux-gnueabihf
apt-get update
apt-get upgrade -y
apt-get install -y autoconf \
automake \
build-essential \
ca-certificates \
curl \
gcc-$GNU_HOST \
g++-$GNU_HOST \
git \
gnupg \
jq \
libssl-dev \
libtool \
meson \
ninja-build \
openssh-client \
pipenv \
pkg-config \
python-dev \
python-pip \
python3-dev \
python3-pip \
unzip \
wget
- 启用 armhf arch 并为其安装 OpenCV deps:
apt-get update
apt-get -y upgrade
dpkg --add-architecture armhf
apt-get update
apt-get install -y gfortran-arm-linux-gnueabihf \
gstreamer1.0-plugins-bad:armhf \
gstreamer1.0-plugins-good:armhf \
libatlas-base-dev:armhf \
libavcodec-dev:armhf \
libavformat-dev:armhf \
libdc1394-22-dev:armhf \
libgstreamer1.0-dev:armhf \
libgstreamer-plugins-base1.0-dev:armhf \
libgtk-3-dev:armhf \
libjpeg-dev:armhf \
libpng-dev:armhf \
libpython2-dev:armhf \
libpython3-dev:armhf \
libswscale-dev:armhf \
libtbb-dev:armhf \
libtbb2:armhf \
libtiff-dev:armhf \
libv4l-dev:armhf \
libxvidcore-dev:armhf \
libx264-dev:armhf \
openexr:armhf \
python-numpy \
python3-numpy
- 设置 pkg-config libdir
HOST_LIBS=/usr/lib
export PKG_CONfig_PATH=
export PKG_CONfig_LIBDIR=$HOST_LIBS/$GNU_HOST/pkgconfig
- 下载 OpenCV
OPENCV_VERSION=4.5.2
OPENCV_DIR=opencv-$OPENCV_VERSION
wget -O opencv.zip \
--progress=bar:force:noscroll \
https://github.com/opencv/opencv/archive/$OPENCV_VERSION.zip
unzip -q opencv.zip
wget -O opencv_contrib.zip \
--progress=bar:force:noscroll \
https://github.com/opencv/opencv_contrib/archive/$OPENCV_VERSION.zip
unzip -q opencv_contrib.zip
- 配置、构建和安装 OpenCV
CROSS_STAGING_PREFIX=/usr/$GNU_HOST/stage
pushd $OPENCV_DIR
OPENCV_BUILD_DIR=platforms/linux/build
mkdir -p $OPENCV_BUILD_DIR
pushd $OPENCV_BUILD_DIR
cmake -Wno-dev -Wno-deprecated \
-G "Ninja" \
-DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=$CROSS_STAGING_PREFIX \
-DCMAKE_BUILD_TYPE=Release \
-DOPENCV_EXTRA_MODULES_PATH=../../../../opencv_contrib-$OPENCV_VERSION/modules \
-DOPENCV_ENABLE_NONFREE=ON \
-DBUILD_PROTOBUF=OFF \
-DPROTOBUF_UPDATE_FILES=ON \
../../..
ninja -j3
ninja install
我需要什么帮助?
此时,我已经尝试了我能想到的所有方法,但我似乎无法找到一种方法来消除这些警告并确保 OpenCV 使用我在编译时安装的库。
基本上,我尝试设置 CMAKE_FIND_ROOT_PATH
(类似于 /usr/arm-linux-gnueabihf
),但这没有帮助,因为当我使用 apt-get install mylib:armhf
时,libs/headers 并没有在那里结束,但是在/usr/lib/arm-linux-gnueabihf
。
然后我尝试将 PKG_CONfig_SYSROOT_DIR
设置为相同的值,但也没有任何运气。
似乎唯一可行的是手动设置每个库,例如:
-DHAVE_JPEG=ON \
-DJPEG_LIBRARY=$HOST_LIBS/$GNU_HOST/libjpeg.so \
-DJPEG_INCLUDE_DIR=$HOST_INCLUDES \
但是我需要为每个库都这样做。
所以我的问题是:有什么方法可以让 cmake 或 pkg-config 在多架构/交叉编译环境中工作吗?
其他信息
我最后得到的 cmake 配置是:
#19 57.95 -- Performing Test HAVE_CXX_WNO_UNUSED_PRIVATE_FIELD - Failed
#19 58.04 --
#19 58.04 -- General configuration for OpenCV 4.5.2 =====================================
#19 58.04 -- Version control: unkNown
#19 58.04 --
#19 58.05 -- Extra modules:
#19 58.06 -- Location (extra): /opencv_contrib-4.5.2/modules
#19 58.06 -- Version control (extra): unkNown
#19 58.06 --
#19 58.06 -- Platform:
#19 58.06 -- Timestamp: 2021-05-13T07:07:53Z
#19 58.07 -- Host: Linux 5.10.25-linuxkit x86_64
#19 58.07 -- Target: Linux 1 arm
#19 58.07 -- CMake: 3.20.2
#19 58.07 -- CMake generator: Unix Makefiles
#19 58.07 -- CMake build tool: /usr/bin/make
#19 58.07 -- Configuration: Release
#19 58.07 --
#19 58.07 -- cpu/HW features:
#19 58.07 -- Baseline:
#19 58.07 -- requested: DETECT
#19 58.07 -- disabled: VFPV3 NEON
#19 58.07 --
#19 58.07 -- C/C++:
#19 58.07 -- Built as dynamic libs?: YES
#19 58.07 -- C++ standard: 11
#19 58.07 -- C++ Compiler: /usr/bin/arm-linux-gnueabihf-g++ (ver 8.3.0)
#19 58.07 -- C++ flags (Release): -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -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
#19 58.07 -- C++ flags (Debug): -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -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
#19 58.07 -- C Compiler: /usr/bin/arm-linux-gnueabihf-gcc
#19 58.07 -- C flags (Release): -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -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
#19 58.07 -- C flags (Debug): -mthumb -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -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
#19 58.07 -- Linker flags (Release): -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,relro -Wl,Now -Wl,--as-needed
#19 58.07 -- Linker flags (Debug): -Wl,--as-needed
#19 58.07 -- ccache: NO
#19 58.07 -- precompiled headers: NO
#19 58.09 -- Extra dependencies: dl m pthread rt
#19 58.09 -- 3rdparty dependencies:
#19 58.09 --
#19 58.09 -- OpenCV modules:
#19 58.10 -- To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python2 python3 quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
#19 58.10 -- disabled: world
#19 58.10 -- disabled by dependency: -
#19 58.10 -- Unavailable: alphamat cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cuDalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv hdf java julia matlab ovis sfm viz
#19 58.10 -- Applications: tests perf_tests apps
#19 58.10 -- Documentation: NO
#19 58.10 -- Non-free algorithms: YES
#19 58.10 --
#19 58.10 -- GUI:
#19 58.10 -- GTK+: YES (ver 3.24.5)
#19 58.10 -- GThread : YES (ver 2.58.3)
#19 58.10 -- GtkGlExt: NO
#19 58.10 --
#19 58.10 -- Media I/O:
#19 58.10 -- ZLib: /usr/arm-linux-gnueabihf/stage/lib/libz.so (ver 1.2.11)
#19 58.10 -- JPEG: libjpeg-turbo (ver 2.0.6-62)
#19 58.10 -- WEBP: build (ver encoder: 0x020f)
#19 58.11 -- PNG: build (ver 1.6.37)
#19 58.11 -- TIFF: build (ver 42 - 4.2.0)
#19 58.11 -- JPEG 2000: build (ver 2.4.0)
#19 58.11 -- HDR: YES
#19 58.11 -- SUNRASTER: YES
#19 58.11 -- PXM: YES
#19 58.11 -- PFM: YES
#19 58.11 --
#19 58.11 -- Video I/O:
#19 58.11 -- DC1394: YES (2.2.5)
#19 58.11 -- FFMPEG: YES
#19 58.11 -- avcodec: YES (58.35.100)
#19 58.11 -- avformat: YES (58.20.100)
#19 58.11 -- avutil: YES (56.22.100)
#19 58.11 -- swscale: YES (5.3.100)
#19 58.11 -- avresample: NO
#19 58.11 -- GStreamer: YES (1.14.4)
#19 58.11 -- v4l/v4l2: YES (linux/videodev2.h)
#19 58.11 --
#19 58.11 -- Parallel framework: pthreads
#19 58.11 --
#19 58.11 -- Trace: YES (with Intel ITT)
#19 58.11 --
#19 58.11 -- Other third-party libraries:
#19 58.11 -- Lapack: NO
#19 58.11 -- Custom HAL: NO
#19 58.11 -- Protobuf: /usr/arm-linux-gnueabihf/stage/lib/libprotobuf.a (3.15.2)
#19 58.12 --
#19 58.12 -- OpenCL: YES (no extra features)
#19 58.12 -- Include path: /opencv-4.5.2/3rdparty/include/opencl/1.2
#19 58.12 -- Link libraries: Dynamic load
#19 58.12 --
#19 58.12 -- Python 2:
#19 58.12 -- Interpreter: /usr/bin/python2.7 (ver 2.7.16)
#19 58.12 -- Libraries: /usr/lib/arm-linux-gnueabihf/libpython2.7.so
#19 58.12 -- numpy: /usr/lib/python2/dist-packages/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
#19 58.12 -- install path: lib/python2.7/dist-packages/cv2/python-2.7
#19 58.12 --
#19 58.12 -- Python 3:
#19 58.12 -- Interpreter: /usr/bin/python3 (ver 3.7.3)
#19 58.12 -- Libraries: /usr/lib/arm-linux-gnueabihf/libpython3.7m.so
#19 58.12 -- numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver undefined - cannot be probed because of the cross-compilation)
#19 58.12 -- install path: lib/python3.7/dist-packages/cv2/python-3.7
#19 58.12 --
#19 58.12 -- Python (for build): /usr/bin/python2.7
#19 58.12 --
#19 58.12 -- Install to: /usr/arm-linux-gnueabihf/stage
#19 58.12 -- -----------------------------------------------------------------
#19 58.12 --
#19 58.84 -- Configuring done
#19 59.97 -- Generating done
#19 60.02 -- Build files have been written to: /opencv-4.5.2/platforms/linux/build
所以它以某种方式找到了视频 I/O 库,即使 cmake 对这些库发出了很多警告。但是,它没有找到媒体 I/O 库(PNG、JPEG 等)和 GTK 库,即使我也安装了这些库。
您也可以在 GitHub 上找到更多上下文opencv/opencv#20076。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)