VSCode配置C语言保姆课
一、mingw-w64下载及配置
1.mingw下载
现在mingw的官网中没有之前的界面了,很容易让大家伙找错版本。所以我就把安装包分享出来吧,对应的是原官网界面中所框选的版本,适配64位操作系统的seh。网盘链接如下:
通过网盘分享的文件:x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z
链接: https://pan.baidu.com/s/1SsyzyDFGCmlzXCzjh6zLiw?pwd=3agp 提取码: 3agp
--来自百度网盘超级会员v5的分享
2.mingw环境配置
复制 bin 目录的路径,形如:L:\C-NIIT\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\mingw64(这个是我的路径,兄弟姐妹们别复制错了)
更改环境变量
点击win,在搜索框中输入环境变量。
3.确认是否配置成功
Win+r后输入cmd调出控制台,输入gcc -v,如下图就成功了。图中所框选和配置环境变量路径一致,即为成功。
二、编写程序
- 自行任意一个盘,并创建一个文件夹,作为父文件夹test1(命名什么都可以)我的是L盘。
- 从Vs code中打开这个父文件夹。
- 新建.vscode文件夹,并在里面新建三个文件,分别为c_cpp_properties.json,launch.json,tasks.json
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "windows-gcc-x64",
"compilerPath": "L:\\C-NIIT\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\bin\\gcc.exe" //自己gdb.exe文件的路径
}
],
"version": 4
}
launch.json
{
"configurations": [
{
"name": "C/C++: gcc.exe 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "L:\\C-NIIT\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\bin",// 自己bin的路径
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "L:\\C-NIIT\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\bin\\gdb.exe",// 自己gdb.exe文件的路径
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc.exe 生成活动文件"
}
],
"version": "2.0.0"
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc.exe 生成活动文件",
"command": "L:\\C-NIIT\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\bin\\gcc.exe",//自己gcc.exe文件的路径
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "L:\\C-NIIT\\x86_64-8.1.0-release-posix-seh-rt_v6-rev0\\mingw64\bin"//自己bin文件的路径
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
通过,上面的操作,你就已经可以成功运行c语言程序了。
三、创建一个属于自己的c语言
#include <stdio.h> /*预处理器指令*/
int main() /*主函数,程序从此开始*/
{
/* 我的第一个 C 程序 */
printf("Hello, World! \n");
return 0; /* 终止main函数,并返回值0 */
}
当Hello, World!输出时,说明你的C语言已经配置成功了