VScode configures C/C++ environment, online debugging

References

Official documentation:

C++ programming with Visual Studio Code

Everyone must learn to study official documents and not be afraid when they see them in English. After all, this is the purest first-hand information.

Recommended by a netizen, very detailed

VSCode configures C/C++ environment - Zhihu (zhihu.com)

Points to note

1. Do not include Chinese in the path;

2. Perform online debugging in the corresponding source file;

3. All the configuration steps in front of the document are mainly to generate a .vscode folder, which contains three json configuration files, which can be copied to any project after finishing;

Here is your reference:

c_cpp_properties.json

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.22621.0",
            "compilerPath": "C:/mingw64/bin/g++.exe",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "intelliSenseMode": "gcc-x64"
        }
    ],
    "version": 4
}

launch.json

{  
    "version": "0.2.0",  
    "configurations": [  
        {  
            "name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示  
            "type": "cppdbg",       // 配置类型,这里只能为cppdbg  
            "request": "launch",    // 请求配置类型,可以为launch(启动)或attach(附加)  
            "program": "${fileDirname}/${fileBasenameNoExtension}.exe",// 将要进行调试的程序的路径  
            "args": [],             // 程序调试时传递给程序的命令行参数,一般设为空即可  
            "stopAtEntry": false,   // 设为true时程序将暂停在程序入口处,一般设置为false  
            "cwd": "${workspaceFolder}", // 调试程序时的工作目录,一般为${workspaceFolder}即代码所在目录  
            "environment": [],  
            "externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台  
            "MIMode": "gdb",  
            "miDebuggerPath": "C:\\mingw64\\bin\\gdb.exe", // miDebugger的路径,注意这里要与MinGw的路径对应  
            "setupCommands": [  
                {   
		            "description": "Enable pretty-printing for gdb",  
                    "text": "-enable-pretty-printing",  
                    "ignoreFailures": true  
                }  
            ],
            "preLaunchTask": "build hello world"//和tasks中label保持一致
        }  
    ]  
}

tasks.json

{
	"version": "2.0.0",
	"tasks": [
		{
			"type": "shell",
			"label": "build hello world",
			"command": "C:/mingw64/bin/g++.exe",
			"args": [
				"-fdiagnostics-color=always",
				"-g",
				"${file}",					 //默认源文件
				"${fileDirname}\\printf.c",  //编译参数,要加入所有的编译的源文件
				"-o",
				"${fileDirname}\\${fileBasenameNoExtension}.exe",
			],
			"options": {
				"cwd": "C:/mingw64/bin"
			},
			"problemMatcher": [
				"$gcc"
			],
			"group": {
				"kind": "build",
				"isDefault": true
			},
			"detail": "编译器: C:/mingw64/bin/g++.exe"
		}
	]
}

Guess you like

Origin blog.csdn.net/Damon_Sandy/article/details/130342473
Recommended