下载链接:
https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/
下载后按步骤安装。
2.下载相关文件在ALL Packages中选中以下三个安装包。
mingw32-gcc.bin(c语言文件编译器) mingw32-gcc-g++.bin(c++语言编译器) mingw32-gdb.bin(调试编译后文件)
选中后点击Installation>applychange,等待安装完成。
3.增加环境变量搜索路径,进入编辑系统环境变量,并点击环境变量
选中系统变量中Path选项,将bin地址加入环境变量,如D:Program Files (x86)MinGWbin
最终结果为
输入cmd打开命令提示符,输入gcc -v,若显示版本号说明安装成功。
二、VSCode安装及配置 1. 安装下载地址:https://code.visualstudio.com/Download
2.安装插件需要安装中文插件和c++插件
直接在扩展中搜索相关插件。
安装完成后重启VSCode
3.配置文件新建test文件夹,在文件夹中新建test.cc,并粘贴以下代码。
#includeint foo(int a) { return a * a; } int main(void) { printf("hello world %dn", foo(5)); return 0; }
点击 运行>以非调试模式运行>c++(GDB/LLDB)>默认配置,自动生成.vscode文件夹和其中的launch.json文件。
将launch.json文件修改成
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
//生成可执行文件
"program": "${workspaceFolder}/test.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
//注释
//"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
//增加重新启动时自动编译操作
"preLaunchTask": "compile"
}
]
}
点击运行>启动调试,弹出找不到任务"compile",点击配置任务>基于模板创建>others,生成tasks.json文件,修改为:
{
// See https://go.microsoft.com/fwlink/?linkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "compile",
"type": "shell",
"command": "g++ test.cc -o test.exe"
}
]
}
再点击运行>启动调试,即可调试程序。



