分目录编译配置记录
launch.json文件
注释处为修改内容
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\out\\${fileBasenameNoExtension}.exe", //1、要与"args"[]下的.exe生成路径一致
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}\\out",//2、指定.exe输出所在目录
"environment": [],
"externalConsole": true,//3、启用黑窗口
"MIMode": "gdb",
"miDebuggerPath": "D:\\Software\\Microsoft VS Code\\mingw64\\bin\\gdb.exe",//4、本机MinGW的gdb.exe的路径
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe 生成活动文件" //5、要与task.json中 "label" 一致
}
]
}
task.json文件:
注释处为修改内容
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",//要与launch.json中 "preLaunchTask" 一致
"command": "D:\\Software\\Microsoft VS Code\\mingw64\\bin\\g++.exe",//本机MinGW的g++.exe的路径
"args": [
"-fdiagnostics-color=always",
"-g",//1、添加编译
"${workspaceFolder}\\src\\*.cpp",//1.1、指定工作目录下.cpp文件位置,执行-g时需要用到
"-I",//2、添加包含
"${workspaceFolder}\\inc",//2.2、指定工目录下.h文件位置,这里只需要包含路径即可,执行-I时需要用到
"-o",//3、添加连接
"${workspaceFolder}\\out\\${fileBasenameNoExtension}.exe"//3.3、指定工目录下链接生成的.exe文件位置与生成名称
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
c_cpp_properties.json文件:
注释处为修改内容
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/inc/**",//1、添加头文件路径(不加也可以,我也不知道为啥)
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
示例截图:
VSCode C/C++ Demo下载链接
参考:
vscode C++ 分文件、文件夹编译配置与错误解决