Clion利用Cmake配置OpenCV总结

cmake_minimum_required(VERSION 3.17)
project(test)

set(CMAKE_CXX_STANDARD 14)

# find required opencv
find_package(OpenCV REQUIRED)
# directory of opencv headers
include_directories(${OpenCV_INCLUDE_DIRS})
#显示OpenCV_INCLUDE_DIRS的值
message(${OpenCV_INCLUDE_DIRS})
# directory of opencv library
link_directories(${OpenCV_LIBRARY_DIRS})

add_executable(test main.cpp)
# opencv libraries
target_link_libraries(test ${OpenCV_LIBS})

 

代码部分解释
find_package(OpenCV REQUIRED)会在Ubuntu系统中找到OpenCVConfig.cmake,该文件定义了OpenCV_INCLUDE_DIRS和OpenCV_LIBS 等变量,因而可以使用 include_directories和target_link_libraries来访问这两个变量。

可以通过打开terminal输入locate OpenCVConfig.cmake来找到这个.cmake文件,用以确认系统确实安装了OpenCV.

你可能感兴趣的:(linux,cmake,opencv,cmake)