OpenCV-CmakeLists.txt编写
# cmake最低版本要求
cmake_minimum_required(VERSION 3.17)
# CXX:C++
project(opencvDemo_test CXX)
#set(CMAKE_CXX_STANDARD 14) 向用户表明当前使用的C++版本
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
set(OPENCV_EXECUTABLE main.cpp test.cpp test10_26.cpp 10_26test.cpp)
# 添加要运行的可执行文件; ${} -> Variable
add_executable(opencvDemo_test ${OPENCV_EXECUTABLE})
#link_directories(D:\\ming_gw\\mingw64\\lib)
#link_directories(D:\\ming_gw\\mingw64\\include)
# 添加opencv路径 注意OpenCV_DIR 后面是""
set(OpenCV_DIR "D:\\opencv4.5.2\\opencv\\build\\install")
link_directories(${OpenCV_DIR})
# find_package -> 自动搜索OpenCV_FOUND :是否找到OpenCV
# OpenCV_INCLUDE_DIRS :OpenCV的头文件目录:可视化文件,源代码可见
# OpenCV_LIBRARY_DIRS :OpenCV的库文件目录:二进制文件,加密性强,头文件中只有声明没有定义,定义写于库文件中
# OpenCV_LIBRARIES :OpenCV的所有库文件列表
find_package(OpenCV REQUIRED)
# 头文件目录
include_directories(
${OpenCV_INCLUDE_DIRS}
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR})
# 运行用的库文件
#set(OpenCV_L opencv_core opencv_imgproc opencv_highgui opencv_imgcodecs)
# 添加可执行文件所需要的库,这个指令用来包含库文件 OpenCV_LIBS == OpenCV_LIBRARIES
target_link_libraries(opencvDemo_test
${OpenCV_LIBS}
# ${OpenCV_LIBRARIES}
)