想要用VSCode高效编写C语言代码?那就跟着这个小教程来配置吧!😎首先,确保你的电脑上已经安装了MinGW-w64工具链,它能帮你编译C程序。下载地址👉[https://sourceforge.net/projects/mingw-w64/]。
接着打开VSCode,点击左侧活动栏中的扩展图标🔍,搜索并安装“C/C++”插件,这是微软官方出品的强大支持工具。安装完成后,在项目文件夹中新建一个`.c`文件,比如`hello.c`。
接下来配置`tasks.json`来告诉VSCode如何编译代码。按快捷键`Ctrl+Shift+P`输入“Tasks: Configure Task”,选择“Create tasks.json file from template”。然后选择“Others”,编辑
```json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "x86_64-w64-mingw32-gcc",
"args": ["${file}", "-o", "${fileDirname}\\${fileBasenameNoExtension}.exe"],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"]
}
]
}
```
保存后,按下`Ctrl+Shift+B`即可运行构建任务。如果一切正常,你会看到输出的可执行文件出现在同一目录下!🎉
最后记得设置调试环境,添加`launch.json`,这样可以直接在VSCode里单步调试代码哦!✨
标签:
免责声明:本文由用户上传,如有侵权请联系删除!