1、安装 mingw64
链接:https://pan.baidu.com/s/1SkrQqLljk_VB-6MMx7rJNw
提取码:c2et
解压后找到文件的地址:如 E:\XXXX\mingw64\bin,将该地址复制到系统环境变量PATH中。
打开CMD,输入 gcc --version,即安装成功
2、VS Code 安装扩展:C/C++,Code Runner
3、 新建一个文件夹,创建任意c文件。
如 hello.c
#include
int main(){
printf("hello world");
return 0;
}
4、点击运行后,生成 .vscode 文件夹 (也可以手动创建),配置三个文件c_cpp_properties.json、launch.json、tasks.json。只有c_cpp_properties.json、launch.json需要修改,其他问价可以直接复制。
① c_cpp_properties.json文件,需要修改E:\XXXX\mingw64\bin为mingw64解压地址。
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**",
"E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++",
"E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/x86_64-w64-mingw32",
"E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include/c++/backward",
"E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include",
"E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/include-fixed",
"E:/XXX/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/BuildTools/VC/Tools/MSVC/14.16.27023/bin/Hostx64/x64/cl.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64"
}
],
"version": 4
}
②launch.json文件
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe", //要运行的文件
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "E:\\XXXX\\mingw64\\bin\\gdb.exe", // E:\XXXX\mingw64\bin为mingw64解压地址
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "complie" // 调试会话开始前执行的任务,类似于Ant,这里为我们的编译任务
}
]
}
③tasks.json文件
{
"version": "2.0.0",
"tasks": [
{
"label": "complie",
"type": "shell",
"command": "gcc",
"args": [
"-g",
"${fileBasename}",
"-o",
"${fileBasenameNoExtension}.exe",
"-lstdc++"
],
"presentation": {
"reveal": "silent"
},
"problemMatcher": "$msCompile"
}
]
}
5、配置完毕,回到hello.c,右键,选择Run Code,即可运行C文件。