{ "configurations": [ { "name": "Linux", "includePath": [ "${workspaceFolder}/**", "/usr/include/opencv4" ], "defines": [], "compilerPath": "/usr/bin/gcc", "cStandard": "c17", "cppStandard": "gnu++14", "intelliSenseMode": "linux-gcc-x64", "mergeConfigurations": false, "browse": { "path": [ "${workspaceFolder}/**" ], "limitSymbolsToIncludedHeaders": true } } ], "version": 4 }
opencv环境配置好
CMakeLists.txt文件
#最低版本要求
cmake_minimum_required(VERSION 3.10)
project(img_operation)
# 找包
find_package(OpenCV REQUIRED)
if(OpenCV_FOUND)
message(STATUS "Found OpenCV")
message(STATUS "Opencv Version:${OpenCV_VERSION}")
message(STATUS "OpenCV Library: ${OpenCV_LIBS}")
message(STATUS "Include path: ${OpenCV_INCLUDE_PATH}")
else()
message(FATAL_ERROT "Could not find OpenCV library")
endif()
#添加可执行文件
add_executable(test_image src/img_operation.cpp)
#添加头文件
target_include_directories(test_image PRIVATE ${OpenCV_INCLUDE_DIRS})
#添加链接库
target_link_libraries(test_image ${OpenCV_LIBS})
遇到的这种问题,在保证opencv配置好的情况下,直接修改一下CMakeList.txt文件,调整一下顺序
多个cpp文件这么写
#添加头文件
include_directories(${OpenCV_INCLUDE_DIRS} PRIVATE ${OpenCV_INCLUDE_DIRS})
#添加链接库
link_libraries(${OpenCV_LIBS} ${OpenCV_LIBS})
#添加可执行文件
add_executable(test_color src/color_format.cpp)
add_executable(test_filtering src/filtering.cpp)