Visual Studio Code 的安装教程和配置C语言环境(详解版)

Visual Studio Code 的安装教程和配置C语言环境(详解版)

最近想装一个VS Code 来写C/C++程序,但是看了网上的很多教程发现并不是那么的好,大部分都尝试失败了,摸索了很久找到了一个比较可靠的方法。

目录

(一)Visual Studio Code 的安装教程

(二)接下来就是C语言的环境配置

(三)补充

首先可以去官网下载VS Code

传送门https://code.visualstudio.com/

(一)Visual Studio Code 的安装教程

1、点击Download for Windows

2、下一步

3、选择安装路径,我选择的是E:\Visual Studio Code

4、下一步

5、这里很重要啦,一定要勾选这个PATH,这样让系统自动去配置这个环境变量,自己就不用再动手去配置了,后面做完全部的工作之后记得重启。

6、接下来就点安装,然后等待安装完成就可以了

(二)接下来就是C语言的环境配置

1、打开Visual Studio Code 界面

先把C/C++的扩展和Chinese简体中文下下来

注:Windows环境下VS code是不支持C语言的调试和编译,所以我们还要下载gcc等Tools的WinGw来提供支撑。

2、接下来就是MinGw的下载和安装

(1)官网的下载地址:[https://sourceforge.net/projects/mingw/]

点击DownLoad即可

如果有小伙伴想跳过这一步也可以直接点击下面这个链接获取:

https://nchc.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/sjlj/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7zhttps://nchc.dl.sourceforge.net/project/mingw-w64/Toolchains%20targetting%20Win64/Personal%20Builds/mingw-builds/8.1.0/threads-posix/sjlj/x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0.7z(记得记得千万别用QQ浏览器下载,推荐使用Edge和火狐)

(2)解压到文件夹下面,我选择的是E盘

(这里要注意了哈)

进入文件夹找到bin文件然后复制路径:E:\x86_64-8.1.0-release-posix-sjlj-rt_v6-rev0\mingw64\bin

(这是我的路径)

(3)配置环境变量

第一步:

第二步:找到Path点击后点击下面的编辑

第三步:把刚刚复制的路径给添加上去

第四步:点击应用,确定就OK了

(4)验证一下MinGw配置完成情况

第一步:Win+R 运行cmd

注意:如果没有重启的话,第一次配置完成的时候运行cmd 直接输入gcc会显示:不是内部或外部命令,也不是可运行的程序或批处理文件。

当然你想完成全部工作之后再重启的话,你也可以输入:

这样表示配置成功了。

第二步:输入gcc -v

这样表示成功了。

(三)补充

有小伙伴说做完上面的步骤之后并没有成功运行C程序。

这是因为我们还没有设置好对应的json文件

配置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

int main(){

printf("hello world");

return 0;

}

F5运行如下:

小三角运行如下:

哦对,别忘记了去扩展里面下一个这个玩意

然后勾选好下面两个选项

OK,到此为止,VS Code的C语言环境你已经配置完成了,赶快去愉快的尝试一下吧!

(配置完成之后,别忘记了重启电脑)

相关任务

Bet中文365 大神f1电池

大神f1电池

📅 08-12 👁️ 3010
365网络科技有限公司 庚的解释

庚的解释

📅 07-06 👁️ 2118
365bet网上娱乐平台 汽车漂移环哪里卖

汽车漂移环哪里卖

📅 10-24 👁️ 1846