Windows 下vscode 配置 C/C++环境
1.安装vscode中C/C++ 插件
2.安装编译调试环境
目前windows下调试仅支持 Cygwin 和 MinGW ,这里使用MinGW
http://mingw-w64.org/doku.php/download
安装好后 打开MinGw安装管理器
选中mingw32-gcc-bin ,mingw32-gcc-g++-bin,ming32-gdb-bin(gcc和g++为c和c++编译器,gdb 必须要选,要不然不能进行调试 )需要在每项右键 Make for Installation选中,然后在菜单栏 Installation 中选择 Apply Changes 进行编译器下载(这个过程需要有网络)
3.配置系统环境
右键'我的电脑' - 属性 环境变量 在系统变量中找到path 点击编辑 然后新建 然后输入MinGW下面bin路径
保存后打开 cmd 输入 gcc -v 查看是否设置成功
4.launch.json 和tasks.json 文件的配置
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
"windows": {
"command": "g++", // c++编译器 如果是要用c编译器的话用 gcc
"args": [
"-g",
"\"${file}\"",
"-o",
"\"${fileDirname}\\${fileBasenameNoExtension}.exe\""
]
}
}
]
}