VSCode 搭建C++编译调试环境主要包括.vscode文件夹下面三个文件,下面是可以调试C++并发编程的配置
- c_cppproperties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:mingw-w64mingw32bingcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
- launch.json
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
// https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg",// 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}/${fileBasenameNoExtension}.exe", // 将要进行调试的程序的路径
"miDebuggerPath": "C:mingw-w64mingw32bingdb.exe", // 修改为本机gdb.exe的路径
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"externalConsole": true,
"environment": [],
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build"
}
]
}
- tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Build",
"command": "C:mingw-w64mingw32bing++.exe", // 修改这里为本机g++路径
"type": "shell",
"args": [
"-g",
"-Wall",
"-std=c++11",
"-lm",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}.exe" //Linux和macOS这里要修改为.o
],
"presentation": {
"reveal": "always",
"echo": true,
"focus": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^(.*):(d+):(d+):s+(warning|error):s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "Run",
"type": "shell",
"dependsOn": "Build",
// "command": "${fileDirname}/${fileBasenameNoExtension}.o",
"command":"${fileDirname}/${fileBasenameNoExtension}.exe",
//"command": "gcc -Wall "$file" -o "$file_base_name" && start cmd /c ""${file_path}/${file_base_name}" & pause"",
// "windows": {
// "command": "${fileDirname}/${fileBasenameNoExtension}.exe"
// },
"args": [],
"presentation": {
"reveal": "always",
"focus": true
},
"problemMatcher": [],
"group": {
"kind": "test",
"isDefault": true
}
}
]
}
- settings.json
{
"files.associations": {
"*.tcc": "cpp",
"istream": "cpp",
"ostream": "cpp",
"iostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"hash_set": "cpp",
"bitset": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"new": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"typeinfo": "cpp",
"thread": "cpp",
"chrono": "cpp"
}
}
下面是mingw的下载地址
https://sourceforge.net/projects/mingw/
http://mingw-w64.org/doku.phpDebug C++ in Visual Studio Codehttp://mingw-w64.org/doku.php
具体可以参考官方的文档 Debug C++ in Visual Studio Code
Debug C++ in Visual Studio Codecode.visualstudio.com