首先我们要现在vscode
和mingw64
安装包
由于网络原因,vscode
和mingw64
的安装包下载比较慢,冲哥这里已经下载好了并上传到了网盘,有需要的可以在后台回复vscode
获取下载链接。
VScode
安装包下载后,直接双击如下,点击同意,然后点击下一步
选择安装路径,然后点击下一步
继续下一步
根据个人需求在框里打勾,然后点击下一步
点击安装
安装好后点击完成
到此,VScode
已经安装完毕
接下来我们安装mingw64
,将冲哥给你们准备好的mingw64
下载后直接解压。将mingw64解压到指定的目录,这个是冲哥的路径D:\Tools\mingw64
解压好之后,还需要配置环境变量
将目录D:\Tools\mingw64\bin追加到环境变量path里
在我的电脑上右击属性,再选择高级系统设置
再点击环境变量
双击path
将刚才的解压路径追加到环境变量里
接下来需要验证mingw64是否配置成功
使用win+R
组合键,输入cmd
回车
在命令行里输入gcc -v
,输出以下版本信息则表示minGW
配置OK
接下来,我们将minGW
配置到vscode
里,首先需要安装一个插件,如下安装C/C++插件
打开一个目录
创建HelloWorld.c测试文件
编写一段测试代码
在目录下创建.vscode
目录(注意有一个点)
在.vscode
目录下创建一下三个配置文件
配置文件里面的内容分别对用如下:
- c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"D:/Tools/mingw64/include/**",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
"D:/Tools/mingw64/include/**",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"D:/Tools/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
]
}
}
],
"version": 4
}
- launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "cmd",
"preLaunchTask": "echo",
"args": [
"/C",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"&",
"echo.",
"&",
"pause"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole":true
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Tools\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
"preLaunchTask": "echo",//这里和task.json的label相对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
- tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileBasenameNoExtension}.exe",
"-fexec-charset=GBK"//解决中文乱码
]
}
],
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
}
配置完后,直接使用快捷键CTRL + F5
运行
运行结果OK,环境配置完成。
如果您觉得本篇文章对您有帮助就顺手点个赞吧
更多干货内容请微信搜索我的个人公众号:C语言中文社区。