vscode C++ opencv配置示例2(cmake)

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/build/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "/usr/bin/gdb",
            "preLaunchTask": "build_cpp",
        }
    ]
}

tasks.json

{
	"version": "2.0.0",
	"options": {
		"cwd":"${workspaceFolder}/build"
	},
	"tasks": [
		{
			"type": "shell",
			"label": "cmake",
			"command": "cmake",
			"args": [".."]
		},
		{
			"type": "shell",
			"label": "make",
			"command":"make",
			"args":[]
		},
		{
			"label":"build_cpp",
			"dependsOrder": "sequence",
			"dependsOn":[
				"cmake",
				"make"
			]
		}
	]
}

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/include/**",
                "/usr/lib/x86_64-linux-gnu/**",
                "/media/a/DATA/Myopencv/include",
                "/media/a/DATA/Myopencv/include/opencv4/opencv2",
                "/media/a/DATA/Myopencv/include/opencv4"
            ],
            
            "defines": [],
            "compilerPath": "/usr/bin/g++",
            "cStandard": "c11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

CMakeLists.txt

PROJECT(main)

CMAKE_MINIMUM_REQUIRED(VERSION 3.4)

SET(CMAKE_BUILD_TYPE Debug)
SET(CMAKE_C_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g")
SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g")

# get the folder of opencv
SET(OpenCV_DIR /media/a/DATA/Myopencv/lib/cmake/opencv4) 
FIND_PACKAGE(OpenCV REQUIRED)

INCLUDE_DIRECTORIES(${OpenCV_INCLUDE_DIRS})

ADD_EXECUTABLE(main main.cpp)
LINK_DIRECTORIES(${OpenCV_LIBRARY_DIRS})

TARGET_LINK_LIBRARIES(main ${OpenCV_LIBS} )

你可能感兴趣的:(环境配置,c++,vscode,opencv)