开篇
昨晚上一不小心给电脑整坏了,无奈之下就重装了系统。装完系统之后最麻烦的当然就是所有学习资料的安装恢复了。这样的工作对我这种记忆力不大好的“老年人”极度不友好!可是这又有什么办法呢,找到了我在云盘的学习资料后,当然是安装对应的工具了。我首先选择恢复的是vscode这款神器,我感觉这款轻量编辑器还是对我挺友好的,各个系统平台都可以使用,支持多种语言不说,还有丰富多样的各类插件免费使用。
配置过程
要拥有vscode这就不用说了吧,没有的话可以去官网下载地址下载,或者使用我提供的蓝奏云链接,密码:5mp1(64位与32位)
https://code.visualstudio.com/#home-terms
https://yunyuwu.lanzouv.com/b00p6w4pi
第一步:汉化vscode并安装c插件
同时摁住(ctrl+shift+x)在搜索框中输入chinese,然后我们点击第一个简体中文下的install,等待下载完成后重启vscode就可以看到汉化后的页面了。然后我们继续安装以下两款插件C/C++
以及Code Runner
第二步:安装编译器(MinGW-W64 GCC)
由于官网下载地址需要科学上网,为了方便我也上传了蓝奏云一份。
官网下载的时候,要下载x86_64-posix-seh
这个版本的o!
https://sourceforge.net/projects/mingw-w64/files/
https://yunyuwu.lanzouv.com/i8aD8xq4muf
第三步:配置环境变量
下载完成后解压到自己想要的目录(路径中不能有中文),然后我们点击到bin文件夹中,复制bin的路径
然后我们点击:此电脑——属性——高级系统设置——环境变量,点击系统环境变量中的Path。接着按下方图片操作后,摁住win+R
键输入cmd
,在cmd控制台输入下方代码并回车,当输出结果如图所示就是成功了
gcc -v -E -x c++ -
第四步:配置vscode
最后我们配置vscode的相关配置:
- 先新建一个文件夹作为C语言项目文件夹,然后点击菜单中的:文件——打开文件夹——选择我们刚创建的文件夹
然后在其中创建一个c语言文件,名字可以随意,结尾必须是.c
- 然后创建一个
.vscode
文件夹(前面有个.)在里面创建三个json文件,分别是:c_cpp_propertise.json
与launch.json
和tasks.json
屏幕截图 2021-12-18 103224.png 分别编辑这三个文件
json 代码:c_cpp_propertise.json
:然后我们需要将图片中红色方框内的路径修改为自己刚安装的编译器的地址,将你刚刚安装的路径复制一下,然后修改此代码中的D:/Programs/mingw64
部分{ "configurations": [ { "name": "Win32", "includePath": [ "${workspaceRoot}", "D:/Programs/mingw64/include/**", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "D:/Programs/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:/Programs/mingw64/include/**", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed", "D:/Programs/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include" ] } } ], "version": 4 }
屏幕截图 2021-12-18 103345.png
launch.json
:将miDebuggerPath属性里的内容一样改为自己的路径
{
"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":"externalTerminal"
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Programs\\mingw64\\bin\\gdb.exe",//自己电脑的gdb路径
"preLaunchTask": "echo",
"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
}
}
第五步:调试
我们输入熟悉的代码然后摁下F5进行调试,就会发现我们可以放飞自我了
c 代码:#include <stdio.h>
int main()
{
printf("hello world");
return 0;
}
总结
总结一下:
1.注意替换路径中的\
与/
改错会闪退的
2.如果要运行c++的话,把launch.json
文件第16行和tasks.json
文件3行的gcc
改成g++