一、首先安装C++环境
- https://blog.csdn.net/xiatutut/article/details/125678300
下面几个文件的说明如:
- https://code.visualstudio.com/docs/cpp/config-mingw
对应参数变量详解:
- https://code.visualstudio.com/docs/editor/variables-reference
需要安装的插件

二、单文件执行及tasks.json文件说明
- 安装对应C/C++插件
- 点击运行后会自动生成.vscode-》tasks.json文件
tasks文件
{
"tasks": [
{
"type": "cppbuild", //执行类型
"label": "C/C++: g++.exe 生成活动文件", //给执行器取一个名字
"command": "C:/lyd_software/mingw64/bin/g++.exe", //执行器的绝对路径,例如mingw64的绝对路径
"args": [ //传给编译器的参数
"-fdiagnostics-color=always",
"-g",
"${file}", //编译当前文件
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe" //生成可执行文件
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
三、基于lunch.json定制化调试

- 主要改:program,miDebuggerPath
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "输入程序名称,例如 ${workspaceFolder}/a.exe", //想要调试的文件
"args": [], //传参数
"stopAtEntry": false, //是否进入main函数时停住
"cwd": "${fileDirname}", //文件工作目录
"environment": [], //环境变量
"externalConsole": false,
"preLaunchTask": "C/C++: cl.exe 生成活动文件", //执行调试之前先执行哪个文件,可以指定为tasks.json里面的label,因为task生成可执行文件,需要先生成可执行文件才能进行debug
"MIMode": "gdb",
"miDebuggerPath": C:/lyd_software/mingw64/bin/gdb.exe", //gdb位置,也就是mingw64位置下gdb位置
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
]
}
三、多文件执行和调试
例如:有多个c++文件需要关联执行,就需要改变tasks.json文件。${workspaceFolder}/*.cpp
- 注意点:需要点到需要执行的文件页面,再进行运行
{
"tasks": [
{
"type": "cppbuild", //执行类型
"label": "C/C++: g++.exe build active file", /给执行器取一个名字,例如mingw64的绝对路径
"command": "C:\\msys64\\ucrt64\\bin\\g++.exe", //执行器的绝对路径mingw64
"args": [ //传给编译器的参数
"-std=c++17", //指定c++版本
"-fdiagnostics-color=always",
"-g",
"${workspaceFolder}/*.cpp", //改为编译当前工作目录下的所有cpp文件
"-o",
"${fileDirname}\\helloworld" //统一生成执行文件,名字叫helloworld,多个文件一起编译为一个
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
四、远程ubuntu开发c++
- 参考:https://code.visualstudio.com/docs/cpp/config-linux
- 首先,安装一个remote -ssh插件
- tasks.json文件
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": ["-g", "${file}", "-o", "${fileDirname}/${fileBasenameNoExtension}"],
"options": {
"cwd": "/usr/bin"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
]
}
- 执行完成后,会编译生成一个同名执行文件,通过./该文件进行执行
VSCode C++配置指南

被折叠的 条评论
为什么被折叠?



