官网:Visual Studio Code - Code Editing. Redefined
下载链接:MinGW-w64 - for 32 and 64 bit Windows - Browse Files at SourceForge.net
解压:
复制bin文件夹所在路径
右键此电脑->属性->高级系统设置->环境变量->选择Path->编辑->新建->粘贴复制的bin路径,最后确定即可
win+r打开运行,输入cmd,输入gcc -v回车。如果出现下图证明成功
1. 新建文件夹作为项目文件,在VSCode中打开文件夹,选择刚刚新建的文件夹,在导航栏中选择新建文件,文件名以.c结尾
2. 再新建一个.vscode文件夹,在里面创建:c_cpp_properties.json、launch.json、tasks.json
c_cpp_properties.json的配置。注意:红框中的路径需要跟据自己编译器的位置进行更改
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceRoot}",
"F:/C/mingw64//include/**",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include"
],
"defines": [
"_DEBUG",
"UNICODE",
"__GNUC__=6",
"__cdecl=__attribute__((__cdecl__))"
],
"intelliSenseMode": "msvc-x64",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "",
"path": [
"${workspaceRoot}",
"F:/C/mingw64//include/**",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/x86_64-w64-mingw32",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include/c++/backward",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include-fixed",
"F:/C/mingw64/lib/gcc/x86_64-w64-mingw32/7.3.0/include"
]
}
}
],
"version": 4
}
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": [],
"externalConsole":true
},
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "F:\\C\\mingw64\\bin\\gdb.exe",// 自己电脑的gdb
"preLaunchTask": "echo",//这里和task.json的label相对应
"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
}
}
编写hello world
关于VSCode中配置C语言的讲解到这里就结束了,如果有什么疑问的地方欢迎留在评论区,谢谢支持~