[英]Can't compile c++ program with OpenCV. OpenCVConfig.cmake file missing
試圖從 CLion 和終端運行我的簡單 cpp 程序,但到處都有同樣的問題:
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.
嘗試了一些解決方案,但沒有任何幫助。 OpenCV 安裝在 macOS 上的用戶目錄中。 有人可以幫助我嗎?
該錯誤消息清楚地指出了解決該問題的方法:首先,找到上述文件之一( OpenCVConfig.cmake
或opencv-config.cmake
)在您系統上的位置。 該路徑將是/path/to/configfile
。 然后相應地設置OpenCV_DIR
變量。
可以通過兩種方式設置變量:
cmake -DOpenCV_DIR=</path/to/configfile> <any additional arguments>
-DENABLE_TESTS=ON
可以將-DOpenCV_DIR=</path/to/configfile>
到CMake選項: 正如錯誤消息所說:
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.
因此,查找文件OpenCVConfig.cmake
並在您的CMakeLists.txt
文件中將變量OpenCV_DIR
設置為包含OpenCVConfig.cmake
文件的目錄。
就我而言,我從源代碼安裝了 opencv。 我安裝opencv的目錄結構如下
opencv-installation-directory/
- bin/
- include/
- lib/
- share/
- OpenCV/
- OpenCVConfig.cmake
所以我CMakeLists.txt
下行添加到CMakeLists.txt
:
set(OpenCV_DIR opencv-installation-directory/share/OpenCV)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.