1.第一步:安装MingW-64
SourceForge网址:https://sourceforge.net/projects/mingw-w64/files/Toolchains%20targetting%20Win32/Personal%20Builds/mingw-builds/installer/mingw-w64-install.exe/download
下载之后如图安装
记下这里的安装路径(建议默认),之后会用到
2.配置变量
依次右键电脑、属性、高级系统设置、环境变量
在系统变量栏新疆C_INCLUDE_PATH如图
C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin
如果安装MingW-64时修改过路径,变量值需做出相应更改
在同一栏打开已经存在的Path
将 C:\Program Files\mingw-w64\x86_64-8.1.0-win32-seh-rt_v6-rev0\mingw64\bin 添加进去
3.安装vs code
微软下载vs code
网址 https://code.visualstudio.com/
疯狂下一步,这里建议全部勾选
4.安装插件
如图在商店搜索插件
建议安装:
Code Runner
C/C++
Beautify
Chinese (Simplified) Language Pack for Visual Studio Code
Code Spell Checker
vscode-icons
5.配置vs code
桌面新建一个文件夹比如 c file,接着在其目录下新建一个名为 .vscode 的文件夹,如图
并在.vscode下新建两个文件,分别命名为launch.json和tasks.json
双击打开launch.json,将以下代码粘贴进去,保存(建议电脑端打开复制)
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gdb.exe",// miDebugger的路径,注意这里要与MinGw的路径对应
"preLaunchTask": "Compile",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
双击打开task.jason,将以下代码粘贴进去,保存
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Compile",
"command": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin\\gcc.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "C:\\Program Files\\mingw-w64\\x86_64-8.1.0-win32-seh-rt_v6-rev0\\mingw64\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
6.开始编程
右键c file选择 open with code
单击这个地方新建C文件,输入名称(包括拓展名)
下面展示Hello world程序,点击右上角小三角在下方终端运行,按F5在在终端中进行运行调试
—————————————————————————————————————————2020/7/2 23:55改