一般配置
在创建了工作区域以后,会有一个.vscode文件夹,里边有launch.json, tasks.json两个文件。
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb)Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}
{
"tasks": [
{
"type": "shell",
"label": "build",
"command": "/usr/bin/g++",
"args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"],
"group": {
"kind": "build",
"isDefault": true
},
}
],
"version": "2.0.0"
}
使用cmake
如果安装了cmake,则需要另外配置一个c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"/usr/include",
"/usr/local/include"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb)Launch",
"type": "cppdbg",
"request": "launch",
// "program": "${workspaceFolder}/${fileBasenameNoExtension}.out",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb",
"preLaunchTask": "make build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
},
]
}
tasks.json
{
"tasks": [
{
"type": "shell",
"label": "make build",
// "command": "/usr/bin/g++",
// "args": ["-g", "${file}", "-std=c++11", "-o", "${fileBasenameNoExtension}.out"],
"command": "cd ./build ;cmake ../ ;make",//编译命令
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "clean",
"type": "shell",
"command": "make clean",
}
],
"version": "2.0.0"
}
windows下使用cmake
launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal",
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\mingw\\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make"
}
]
}
task.json
{
"version": "2.0.0",
"options": {
"cwd": "${workspaceRoot}/build"
},/指定命令执行所在路径
"tasks": [
{
"label": "cmake",
"type": "shell",
"command": "cmake",
"args": [
"-G",
"MinGW Makefiles",
".."
],
},
{
"label": "make",/要执行的第二个make命令
"type": "shell",
"command": "mingw32-make",
"args": [],
"group": {
"kind": "build",
"isDefault": true
},
"dependsOn":["cmake"],///指定,在执行make之前,需先执行cmake
},
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\mingw\\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0\\mingw64\\bin\\g++.exe",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64",
"configurationProvider": "vector-of-bool.cmake-tools"
}
],
"version": 4
}