升级到macOS Catalina后,使用cmake构建C ++的opencv4失败

问题描述

嗨,我正在尝试使用cmake从源代码构建opencv4(在https://thecodinginterface.com/blog/opencv-cpp-vscode/之后)。我将macOS更新到10.15,并安装了最新的xcode。我git克隆了存储库,并创建了如下的构建目录,然后尝试配置cmake:

$ mkdir opencv
$ cd opencv
$ git clone https://github.com/opencv/opencv.git
$ cd opencv
$ git checkout tags/4.2.0
$ cd ..
$ git clone https://github.com/opencv/
$ cd opencv_contrib 
$ git checkout tags/4.2.0
$ cd ..


$ cd build_opencv
$ cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=../install \
      -D INSTALL_C_EXAMPLES=ON \
      -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ../opencv

我收到以下错误,似乎正在尝试查找此不存在的路径:

“ / Library / Developer / CommandLinetools / SDKs / MacOSX10.14.sdk / System / Library / Frameworks / OpenGL.framework”

我已经将Mac版本更新为10.15,但它似乎正在MacOSX10.14下搜索路径。我在网上看过,但似乎找不到任何建议?

CMake Error in /usr/local/include/opencv/build_opencv/CMakeFiles/CMakeTmp/CMakeLists.txt:
  Imported target "VTK::RenderingOpenGL2" includes non-existent path

    "/Library/Developer/CommandLinetools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted,renamed,or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



CMake Error in /usr/local/include/opencv/build_opencv/CMakeFiles/CMakeTmp/CMakeLists.txt:
  Imported target "VTK::RenderingOpenGL2" includes non-existent path

    "/Library/Developer/CommandLinetools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks/OpenGL.framework"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted,or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



CMake Error at cmake/OpenCVDetectVTK.cmake:73 (try_compile):
  Failed to generate test project build system.
Call Stack (most recent call first):
  CMakeLists.txt:767 (include)


-- Configuring incomplete,errors occurred!

解决方法

下载并安装

用于XCode 12的命令行工具

来自apple developer tools downloads

它曾经工作过,您可以执行Very long name Very long … Very long name|truncatewords:2 并且可以为您执行,但是现在出现错误,提示它找不到包或类似的东西。因此,必须采用这种方法。