1、打开Visual Studio Code 界面
先把C/C++的扩展安装
注:Windows环境下VS code是不支持C语言的调试和编译,所以我们还要下载gcc等Tools的WinGw来提供支撑。
2、接下来就是MinGw的下载和安装
(1)官网的下载地址:[https://sourceforge.net/projects/mingw/]
点击DownLoad即可
链接:https://pan.baidu.com/s/1gCTvFxa4V8NQ3szQYJXmwA?pwd=9999
提取码:9999
或者网盘:阿里云盘分享https://www.alipan.com/s/ZWyzg2ybNXM
(2)解压到文件夹下面,我选择的是E盘
(这里要注意了哈)
进入文件夹找到bin文件然后复制路径:E:\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0\mingw64\bin
(这是我的路径)
(3)配置环境变量
第一步打开此电脑,单击右键,点击属性,找到高级系统属性,点击高级,找到环境变量,在系统变量中找到Path一栏,
另外:
配置JSON文件
第一步:在磁盘下创建一个文件夹,命名为CWORKSPACE
第二步:在VS Code中的资源管理器下面创建几个文件,因为我这里已经创建好了就直接展示出来吧。
(1)在CWORKSPACE文件下面新建一个文件夹命名为 .vscode
(2)在.vscode文件夹下面创建三个json文件。
命名为:
1、c_cpp_properties.json
2、launch.json
3、tasks.json
(3)修改Json文件中的内容
1、c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/include/**",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/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}",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/include/**",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
]
}
}
],
"version": 4
}
将其中的 E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin 路径替换成你的路径
2、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": [],
"console":"newExternalWindow"
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "E:\\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
"preLaunchTask": "echo",//这里和task.json的label相对应
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
这里同样修改E:/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0/mingw64/bin 路径替换成你的路径
3、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": "new",
"showReuseMessage": true,
"clear": false
}
}
4)运行C程序的Hello world程序
#include<stdio.h>
int main(){
printf("hello world");
return 0;
}
另外:
去扩展里面下一个这个玩意
然后勾选好下面两个选项
OK,到此为止,VS Code的C语言环境你已经配置完成了,赶快去愉快的尝试一下吧!
(配置完成之后,别忘记了重启电脑)