环境配置的坑(一)Cmake :: Could not find a package configuration file provided by "xxx"

可能是放置文件问题。

不是说你路径配置错了,可能就算是路径是对的,但是你放到了系统文件夹里(Program Files 和 Program Files (x86))。

然后当你用Cmake编译时候就会报错。我以配置opencv为例:

一开始我将opencv放入Program Files 中:

set(OpenCV_DIR C:/Program Files/opencv-3.40/build)
find_package(OpenCV REQUIRED)

但是Cmake报错:

CMake Error at CMakeLists.txt:19 (find_package):
  By not providing "FindOpenCV.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "OpenCV", but
  CMake did not find one.

  Could not find a package configuration file provided by "OpenCV" with any
  of the following names:

    OpenCVConfig.cmake
   
opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If "OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.

接着我就想是不是路径中空格的问题,改为:

set(OpenCV_DIR C:/Program\ Files/opencv-3.40/build)
find_package(OpenCV REQUIRED)

还是不行还是报错,而且还是同样的错。

这我就奇怪了,明明上次还好好的为什么这次偏偏就不行。(上次用的是opencv3.0这次是opencv3.4)。

后来我就改成上次的opencv3.0,可以找到了,只是版本不对。(3.0不对vc15(即vs2017))。

后来我把文件夹直接放在C:下面,然后再把路径改为当前路径:

set(OpenCV_DIR C:/opencv-3.40/build)
find_package(OpenCV REQUIRED)

结果就成了。:

OpenCV ARCH: x64
OpenCV RUNTIME: vc15
OpenCV STATIC: ON
Found OpenCV: C:/opencv-3.40/build (found version "3.4.0") 
Found OpenCV 3.4.0 in C:/opencv-3.40/build/x64/vc15/lib
You might need to add C:\opencv-3.40\build\x64\vc15\bin to your PATH to be able to run your applications.
Configuring done


请留言,鼓励也好,指教,想问我问题更好。

关注我,留言给我,我肯定会回复你的。


 

你可能感兴趣的:(环境配置,Cmake)