两步搭建vscode linux C语言编辑环境

两步搭建vscode linux C语言编辑环境


在开始之前,请先确保已经下载了vscode中的C/C++插件(没有下载的话在插件搜索框中搜)。vscode打开一个文件夹,此时底端的横条为蓝色(只打开文件没有打开文件夹的话,横条为紫色)。新建一个.c文件。

launch.json文件配置

单击菜单栏上的Debug菜单,再单击"open configuration"选项
launch.jason文件配置第一步在上方中间会出现一个小横条,选择C++(GDB/LLDB)选项
launch.json文件配置第二步
接着再选gcc build and debug active file选项
launch.json文件配置第三步选好之后,会自动生成并打开launch.json文件。其默认配置如下:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "gcc build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}/${fileBasenameNoExtension}",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "gcc build active file",
            "miDebuggerPath": "/usr/bin/gdb"
        }
    ]
}

直接使用默认配置即可。保存退出。

配置tasks.json文件

还是单击菜单栏上的Debug菜单。选择Start Debugging或者Start Without Debuging选项。此处选择了Start With Debugging,并在程序代码中设置了断点。

task.json文件配置第一步会弹出提示框说找不到任务"gcc build active file":
提示框选择Configure Task。在上方中间会出现一个选项框:
步骤二选择C/C++: gcc build active file。自动会生成tasks.json文件。其默认配置如下:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "gcc build active file",
            "command": "/usr/bin/gcc",
            "args": [
                "-g",
                "${file}",
                "-o",
                "${fileDirname}/${fileBasenameNoExtension}"
            ],
            "options": {
                "cwd": "/usr/bin"
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]
}

保存一下。
回到.c文件界面,按F5就可以进行调试了。
在这里插入图片描述
完)

  • 5
    点赞
  • 40
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值