Windows 10上的CLion,MinGW-64和CMake“需要OpenCV,但未找到某些标头或库”

时间:2018-09-08 22:23:28

标签: c++ opencv cmake mingw clion

我一直在尝试用CLion正确设置OpenCV的尝试,但收效甚微,因此请提出要求。

这是我的CMakeList的样子:

cmake_minimum_required(VERSION 3.12)
project(ocv_test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

find_package(OpenCV REQUIRED)

set(SOURCE_FILES main.cpp)
add_executable(ocv_test ${SOURCE_FILES})

include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(ocv_test ${OpenCV_LIBS})

这是我得到的错误:

"C:\Program Files\JetBrains\CLion 2018.2.2\bin\cmake\win\bin\cmake.exe" -DCMAKE_BUILD_TYPE=Debug -G "CodeBlocks - MinGW Makefiles" C:\Users\Owner\CLionProjects\ocv-test
Could not find OpenCV_CORE_INCLUDE_DIR
Could not find OpenCV_HIGHGUI_INCLUDE_DIR
Include dir: OFF
CMake Error at C:/Program Files/JetBrains/CLion 2018.2.2/bin/cmake/win/share/cmake-3.12/Modules/FindOpenCV.cmake:220 (MESSAGE):
  OpenCV required but some headers or libs not found.  Please specify it's
  location with OpenCV_ROOT_DIR env.  variable.
Call Stack (most recent call first):
  CMakeLists.txt:6 (find_package)


-- Configuring incomplete, errors occurred!
See also "C:/Users/Owner/CLionProjects/ocv-test/cmake-build-debug/CMakeFiles/CMakeOutput.log".

我主要是从另一个SO答案关注these steps,但步骤如下:

  1. 已安装MinGW-64
    • 体系结构:x86_64,线程:posix,异常:sjlj
  2. 已安装CMake 3.12.2 x64 msi
  3. 在系统变量中,设置/创建以下内容:
    • _CMAKE_HOME(C:\ Program Files(x86)\ CMake)
    • _MINGW_HOME(C:\ mingw \ mingw64)
  4. 然后,将以下内容添加到Path变量中:
    • %_ CMAKE_HOME%\ bin
    • %_ MINGW_HOME%\ bin
  5. 下载OpenCV 3.4.3,然后解压缩到:
    • C:\ opencv \ opencv-3.4.3
  6. 使用CMake,配置w / MinGW Makefile并指定本机编译器:
    • C:C:/mingw/mingw64/bin/x86_64-w64-mingw32-gcc.exe
    • C ++:C:/ mingw / mingw64 / bin / x86_64-w64-mingw32-g ++。exe
  7. 然后,生成(不包含测试,文档,Python,WITH_IPP,WITH_MSMF)以:
    • C:_dev_sw \ opencv \ opencv-3.4.3 \ build_mingw
  8. 运行mingw32-make,然后在C:_dev_sw \ opencv \ opencv-3.4.3 \ build_mingw中安装mingw32-make
  9. 在系统变量中,设置/创建以下内容:
    • _OPENCV_HOME(C:\ opencv \ opencv-3.4.3 \ build_mingw \ install \ x64 \ mingw)
  10. 然后,将以下内容添加到Path变量中:
    • %_ OPENCV_HOME%\ bin
  11. FindOpenCV.cmake添加到:
    • C:\ Program Files \ JetBrains \ CLion 2018.2.2 \ bin \ cmake \ win \ share \ cmake-3.12 \ Modules
  12. 在CLion中创建新的C ++可执行项目(ocv测试)
  13. 更新MakeLists.txt文件(请参见上文)
  14. 重新加载MakeLists.txt并获取上面显示的错误

我尝试如下更新CMakeList,但仍然存在相同的错误:

cmake_minimum_required(VERSION 3.12)
project(ocv_test)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

# Where to find CMake modules and OpenCV
set(OpenCV_DIR "C:\\opencv\\opencv-3.4.3\\build_mingw\\install")
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")

find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})

add_executable(ocv_test main.cpp)

# add libs you need
set(OpenCV_LIBS opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)

# linking
target_link_libraries(ocv_test ${OpenCV_LIBS})

this答案不同,我在CMake版本中看不到OpenCV_DIR名称。另外,我尝试将_OPENCV_HOME更新为OpenCV_ROOT_DIR(如错误所述),但这也不起作用。

似乎有什么异常吗?

===

编辑1:

FindOpenCV是问题所在(因此跳过步骤11)。在CMakeLists中设置OPENCV_DIR var可以修复错误,并且可以成功构建(感谢Tsyvarev!)。

我不确定如果在其他PC和/或OS上运行项目,则在CMakeLists中设置OPENCV_DIR是否会成为问题,因此我在CMake GUI中添加了OPENCV_DIR条目(指向/ install目录),重复步骤6- 8,创建了新的但类似的CLion项目,并收到以下错误:

CMake Error at CMakeLists.txt:10 (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.

同样,如果我设置OPENCV_DIR变量,此问题将得到解决。但是,由于已经在GUI中进行了配置,如何避免这种情况?

0 个答案:

没有答案