[openCV/C++/CMake]如何在Clion中利用CMake编译openCV

【——概览——】

[openCV/C++/CMake]如何在Clion中利用CMake编译openCV_第1张图片


【——配置——】 

 在"CMakeLists.txt"中输入如下语句:

cmake_minimum_required(VERSION 3.23)

project(opencvTask1)

set(CMAKE_CXX_STANDARD 14)

set(OpenCV_DIR D:/Clion/openCV/build/x64/vc15/lib)

find_package(OpenCV REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

link_libraries(${OpenCV_LIBS})

add_executable(Project1 main.cpp)

【——注解——】

cmake_minimum_required(VERSION 3.23)

"3.23"为所需CMake的最低版本

project(opencvTask1)

"opencvTask1"为项目名称

set(CMAKE_CXX_STANDARD 14)

"14"为当前CMake版本对应的STANDARD

set(OpenCV_DIR D:/Clion/openCV/build/x64/vc15/lib)

"D:/Clion/openCV/build/x64/vc15/lib"为openCV的lib路径

(内含"openCVConfig.cmake"文件)

find_package(OpenCV REQUIRED)

自动在上述"OpenCV_DIR"路径中寻找"openCVConfig.cmake"文件(支持各种版本的openCV)

 include_directories(${OpenCV_INCLUDE_DIRS})

提供openCV头文件路径

link_libraries(${OpenCV_LIBS})

链接静态库

add_executable(Project1 main.cpp) 

"Project1 main.cpp"为当前C++程序的cpp格式文件名


 【——加载——】

加载CMake项目,输出如下则配置成功 

你可能感兴趣的:(openCV,C++,CMake,opencv,c++,python)