OpenCV 编译正确,但在 .deb 打包过程中失败

OpenCV 编译正确,但在 .deb 打包过程中失败

尝试按照一些教程在 Ubuntu 18.04 中为较新版本的 OpenCV 构建 .deb 包。步骤如下:

wget https://github.com/opencv/opencv/archive/4.1.0.zip
unzip 4.1.0.zip
cd opencv-4.1.0
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DOPENCV_GENERATE_PKGCONFIG=ON -DCMAKE_INSTALL_PREFIX=/usr/local ..

此时我编辑 CMakeCache.txt 文件,并将此行从 修改OFFON

CPACK_BINARY_DEB:BOOL=ON

下一步成功编译所有内容,但在创建 .deb 包时失败:

make -j4 package

这是其生成的包含错误消息的输出尾部:

Run CPack packaging tool...
CPack: Create package using DEB
CPack: Install projects
CPack: - Run preinstall target for: OpenCV
CPack: - Install project: OpenCV
CPack: -   Install component: dev
CPack: -   Install component: java
CPack: -   Install component: libs
CPack: -   Install component: licenses
CPack: -   Install component: python
CPack: -   Install component: scripts
CPack: Create package
CPackDeb: - Generating dependency list
CMake Error at /usr/share/cmake-3.10/Modules/CPackDeb.cmake:709 (message):
  CPackDeb: dpkg-shlibdeps: '
  dpkg-shlibdeps: error: cannot find library libopencv_calib3d.so.4.1 needed by ./usr/bin/opencv_interactive-calibration (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '/usr/local/lib')
  dpkg-shlibdeps: error: cannot find library libopencv_features2d.so.4.1 needed by ./usr/bin/opencv_interactive-calibration (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '/usr/local/lib')
  dpkg-shlibdeps: error: cannot find library libopencv_highgui.so.4.1 needed by ./usr/bin/opencv_interactive-calibration (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '/usr/local/lib')
  dpkg-shlibdeps: error: cannot find library libopencv_videoio.so.4.1 needed by ./usr/bin/opencv_interactive-calibration (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '/usr/local/lib')
  dpkg-shlibdeps: error: cannot find library libopencv_imgproc.so.4.1 needed by ./usr/bin/opencv_interactive-calibration (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '/usr/local/lib')
  dpkg-shlibdeps: error: cannot find library libopencv_core.so.4.1 needed by ./usr/bin/opencv_interactive-calibration (ELF format: 'elf64-x86-64' abi: '0201003e00000000'; RPATH: '/usr/local/lib')
...cut lots more...
  dpkg-shlibdeps: error: cannot continue due to the errors listed above
  Note: libraries are not searched in other binary packages that do not have any shlibs or symbols file.
  To help dpkg-shlibdeps find private libraries, you might need to use -l.
  ';
  executed command: '/usr/bin/dpkg-shlibdeps --ignore-missing-info -O ./usr/bin/opencv_annotation;./usr/bin/opencv_interactive-calibration;./usr/bin/opencv_version;./usr/bin/opencv_visualisation';

有人能解释一下我必须做什么才能创建 OpenCV .deb 文件吗?

答案1

回答得有点晚,但我来到这里是因为我正在寻找 nVidia Jetson Nano 上相同问题的答案。最后,我挖了一点东西才解决它。以下是我成功构建包的方法.deb

在“cmake”并打开标志后CPACK_BINARY_DEB:BOOL

  1. make第一的。

  2. 编辑CPackConfig.cmake构建目录中的文件

    1. 注释掉这句话set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "TRUE")——借用自这个 Mozilla 服务 lua_sandbox已解决的问题。
    2. 将所有出现的unknown(version) 替换为4.1.0
  3. 编辑CPackSourceConfig.cmake以将所有出现的unknown(version) 替换为4.1.0

  4. make package

步骤 1 允许软件包工具找到需要首先构建的缺失库依赖项。步骤 2 中的第一个编辑允许构建 deb 软件包,其他编辑允许构建带有数字版本号的软件包(这是未来升级的正确做法),否则会出现dpkg问题。

答案2

您需要make install在拨打电话之前先拨打电话make package

答案3

我获得的最佳信息来自 opencv 文档教程 Linux 安装教程配置参考

我最终使用以下步骤来构建.deb 包:

# Install basic tools
sudo apt install -y g++
sudo apt install -y cmake
sudo apt install -y make
sudo apt install -y git

# Clone repo and make build folder
git clone https://github.com/opencv/opencv.git
cd opencv
git checkout 4.x
mkdir -p build && cd build

# create files from cmake
cmake .. \
 -DCPACK_BINARY_DEB=ON \
 -DCMAKE_BUILD_TYPE=Release \
 -DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)

# Install files before building .deb package
sudo make install
cpack -G DEB
sudo make uninstall

相关内容