CMakeLists.txt 项目模式(只有一个main函数入口)
cmake_minimum_required(VERSION 3.5)
project(vsin01 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OpenCV_DIR G:/MinGW_Opencv/opencv4.10/opencv4.10_MinGW_Release_x64_mingw1120_64/x64/mingw/lib)#库路径你自己换成你电脑上的
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# 包含 Eigen 头文件目录
include_directories("G:/eigen-3.4.0")
# 查找项目中的所有 .cpp 源文件,排除 CMake 生成目录
file(GLOB_RECURSE SOURCES
${CMAKE_SOURCE_DIR}/*.cpp
${CMAKE_SOURCE_DIR}/*.hpp
)
# 手动排除掉 CMake 生成的 CMakeFiles 目录
list(FILTER SOURCES EXCLUDE REGEX "/CMakeFiles/")
# 将找到的文件添加到可执行文件中
add_executable(MYCODE ${SOURCES})
target_link_libraries(MYCODE PRIVATE ${OpenCV_LIBS})
CMakeLists.txt 单文件模式,可以有多个main函数入口
cmake_minimum_required(VERSION 3.5)
project(vsin01 VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(OpenCV_DIR D:/Buildok/opencv4.10_MinGW_Release_x64_mingw1120_64/x64/mingw/lib)#库路径你自己换成你电脑上的
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
set(PROJECT_SOURCES
sss.cpp
)
add_executable(CMVS
${PROJECT_SOURCES}
)
target_link_libraries(CMVS PRIVATE ${OpenCV_LIBS})
关于编译器的选择,如果不能选择mingw编译器可以把项目关闭,改名,再重新打开