Linux使用VScode配置C++和opencv

一、扩展商店搜索C++安装

二、配置用于编译的tasks.json文件

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "shell: g++ build active file",
			"command": "/usr/bin/g++",
			"args": [
				"-g",
				"${file}",
				"-o",
				"${fileDirname}/${fileBasenameNoExtension}",
				"`pkg-config", "--cflags", "--libs", "opencv4`",
				

				

			],
			"options": {
				"cwd": "/usr/bin"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			}
		}
	]
}
这一行是把opencv库链接到VSCode,注意中间的逗号,在命令行中是:
g++ hello.cpp -o hello `pkg-config --cflags --libs opencv4
在VSCode是:
"`pkg-config", "--cflags", "--libs", "opencv4`",

三、配置用于代码提示的c_cpp_properties.json文件

{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**",
                "/usr/local/include/",
				"/usr/local/include/opencv4",
				"/usr/local/include/opencv4/opencv2"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/gcc",
            "cStandard": "gnu11",
            "cppStandard": "gnu++14",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

这时已经生成了一个hello.o文件

四、配置用于的调试launch.json文件

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) 启动",
            "type": "cppdbg",
            "request": "launch",
            "program":"${fileDirname}/${fileBasenameNoExtension}.o",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "为 gdb 启用整齐打印",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }
    ]
}

猜你喜欢

转载自blog.csdn.net/qq_41968669/article/details/106352911