vscode配置C/C++编译器
安装vscode和MinGW
进入vscode官网下载windows下的vscode安装包:
-
点击vscode下载;
-
安装C++扩展;
-
进入MinGW下载下载windows下的MinGw6,我这里选x86_64-posix-sjlj,下载完后解压到电脑。
-
添加到系统路径
-
测试是否安装成功,win+R打开cmd,输入gcc -v测试
配置vscode
- 打开文件夹,新建vscode文件夹,和launch.json,tasks.json,c_cpp_properties.json三个文件
- 配置launch.json
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb)Launch", //配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", //配置类型,只能为cppdbg
"request": "launch", //请求配置类型 launch为(启动),attach为(附加)
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe", //将调试的程序路径
"args":[], //程序调式传给程序的命令行参数,一般为空
"stopAtEntry": false, //设置为true程序暂停在程序入口,一般为false
"cwd": "${workspaceFolder}",//调式的工作目录 %{workspaceFolder}代表程序所在路径
"environment": [],
"externalConsole": false, //调试是否显示控制台
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe", //miDebugger路径
"setupCommands":[
{
"description": "启动整齐打印",
"text":"-enable-pretty-printing",
"ignoreFailures": false
}
],
// "preLaunchTask": "C/C++: gcc.exe 生成活动文件" //预加载
}
]
}
3.配置tasks.json
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "C:\\MinGW\\bin\\g++.exe", //编译器选择,c++用g++,c用gcc
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\Debugger\\${fileBasenameNoExtension}.exe", //编译后的文件存放
],
"options": {
"cwd": "C:\\MinGW\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "编译器: C:\\MinGW\\bin\\g++.exe"
}
]
}
4.配置c_cpp_properties.json
{
"configurations": [
{
"name": "win",
"includePath": [
"${workspaceFolder}/**" //包含目录,预编译导入
],
"defines": [],
"compilerPath": "C:\\MinGW\\bin\\g++.exe", //编译器路径
"cStandard":"c11",
"cppStandard": "c++17",
"intelliSenseMode": "${default}"
}
],
"version": 4
}
测试代码调试
成功!