使用 make install 在 Raspbian Raspberry Pi 中安装 OpenCV 4 时出现编译错误 3+

Compiling error using make install to install OpenCV 4 in Raspbian Raspberry Pi 3+

`您好,我已经在 Raspberry 上安装了几次 OpenCV。然而,由于一切都在不断发展(OS、图书馆等)。这次我收到以下错误:

-- Installing: /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so
CMake Error at modules/python2/cmake_install.cmake:61 (file):
  file RPATH_CHANGE could not write new RPATH:

    /usr/local/lib

  to the file:

    /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so

  No valid ELF RPATH or RUNPATH entry exists in the file; Error reading ELF
  identification.
Call Stack (most recent call first):
  modules/cmake_install.cmake:162 (include)
  cmake_install.cmake:95 (include)


Makefile:83: recipe for target 'install' failed
make: *** [install] Error 1

我尝试了以下脚本:

    sudo apt-get upgrade
    sudo apt-get install -y build-essential cmake pkg-config
    sudo apt-get install -y libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
    sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
    sudo apt-get install -y libxvidcore-dev libx264-dev
    sudo apt-get install -y libgtk2.0-dev
    sudo apt-get install -y libatlas-base-dev gfortran
    sudo apt-get install -y python2.7-dev python3-dev
    cd ~
    #wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.1.0.zip
    #unzip opencv.zip
    #wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
    #unzip opencv_contrib.zip
    git clone https://github.com/opencv/opencv.git
    git clone https://github.com/opencv/opencv_contrib.git
    pip install numpy
    cd ~/opencv
    mkdir build
    cd build
    cmake -D CMAKE_BUILD_TYPE=RELEASE \
        -D CMAKE_INSTALL_PREFIX=/usr/local \
        -D INSTALL_PYTHON_EXAMPLES=ON \
        -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
        -D BUILD_EXAMPLES=ON ..

    make -j4
    sudo make install
    sudo ldconfig

我希望库能够正确编译,但是控制台显示的是这样的:

-- Up-to-date: /usr/local/lib/libopencv_stitching.so.4.1
-- Up-to-date: /usr/local/lib/libopencv_stitching.so
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/warpers.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/autocalib.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/blenders.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/camera.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/exposure_compensate.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/matchers.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/motion_estimators.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/seam_finders.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/timelapsers.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/util.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/util_inl.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/warpers.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stitching/detail/warpers_inl.hpp
-- Up-to-date: /usr/local/lib/libopencv_superres.so.4.1.0
-- Up-to-date: /usr/local/lib/libopencv_superres.so.4.1
-- Up-to-date: /usr/local/lib/libopencv_superres.so
-- Up-to-date: /usr/local/include/opencv4/opencv2/superres.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/superres/optical_flow.hpp
-- Up-to-date: /usr/local/lib/libopencv_tracking.so.4.1.0
-- Up-to-date: /usr/local/lib/libopencv_tracking.so.4.1
-- Up-to-date: /usr/local/lib/libopencv_tracking.so
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/feature.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/kalman_filters.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/onlineBoosting.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/onlineMIL.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/tldDataset.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/tracker.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/tracking/tracking.hpp
-- Up-to-date: /usr/local/lib/libopencv_stereo.so.4.1.0
-- Up-to-date: /usr/local/lib/libopencv_stereo.so.4.1
-- Up-to-date: /usr/local/lib/libopencv_stereo.so
-- Up-to-date: /usr/local/include/opencv4/opencv2/stereo.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stereo/descriptor.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stereo/matching.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stereo/quasi_dense_stereo.hpp
-- Up-to-date: /usr/local/include/opencv4/opencv2/stereo/stereo.hpp
-- Up-to-date: /usr/local/lib/python2.7/dist-packages/cv2/__init__.py
-- Up-to-date: /usr/local/lib/python2.7/dist-packages/cv2/load_config_py2.py
-- Up-to-date: /usr/local/lib/python2.7/dist-packages/cv2/load_config_py3.py
-- Up-to-date: /usr/local/lib/python2.7/dist-packages/cv2/config.py
-- Installing: /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so
CMake Error at modules/python2/cmake_install.cmake:61 (file):
  file RPATH_CHANGE could not write new RPATH:

    /usr/local/lib

  to the file:

    /usr/local/lib/python2.7/dist-packages/cv2/python-2.7/cv2.so

  No valid ELF RPATH or RUNPATH entry exists in the file; Error reading ELF
  identification.
Call Stack (most recent call first):
  modules/cmake_install.cmake:162 (include)
  cmake_install.cmake:95 (include)


Makefile:83: recipe for target 'install' failed
make: *** [install] Error 1`

如有任何帮助,我们将不胜感激。为了很多人的心理健康,我会把编译后的图片备份上传。

我也 运行 遇到了这个错误,并且能够使用以下步骤解决它:

  1. 导航到您的 OpenCV 目录(运行ning cd .. 从您的 build 目录)。

  2. 运行以下命令:

    python ./modules/python/src2/gen2.py ./build/modules/python_bindings_generator ./build/modules/python_bindings_generator/headers.txt`
    
  3. 导航回您的构建目录并再次运行sudo make install

假设您从 build 目录中 运行 您的 cmake 命令,这次它应该可以工作。

我尝试了很多东西并解决了问题。 Raspbian Stretch + OpenCV 4 的图像可以在这里找到:

https://drive.google.com/open?id=1UpHp4hR0_mCSU4OS2OLGzebA_4zyBdqf