VSCode配置C/C++编译

本文介绍了如何在VSCode中配置C/C++的编译环境,包括使用cygwin和makefile、cmake进行工程编译,以及设置task.json和launch.json进行代码调试。VSCode的优点在于强大的代码提示,但缺点是缺少重命名重构和查找引用的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

安装VSCode

1.下载地址: https://code.visualstudio.com/
2. 配置C/C++的编译环境: https://code.visualstudio.com/docs/languages/cpp

VSCode + cygwin + makefile编译C/C++工程

VSCode的task.json 编译.c文件需要一个个将文件添加在 task中,如果文件很多这样并不方便,所有如果文件多的话最好是用makefile编译。

1.代码编译

安装好cygwin,编写好makefile,然后调用make。
方法1: 直接在terminal,调用make
方法2:配置task任务,调用make
task.jason:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "make",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": [
                "$gcc"
            ]
        }
    ]

}

2. 调试

如果要调试程序,编译代码是CFLAGS标识要加 “-g”,然后配置lauch.jason, 如下

{
// 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”: “(gdb) Launch”,
“type”: “cppdbg”,
“request”: “launch”,
“program”: “ w o r k s p a c e F o l d e r / m a i n . e x e " , " a r g s " : [ ] , " s t o p A t E n t r y " : f a l s e , " c w d " : " {workspaceFolder}/main.exe", "args": [], "stopAtEntry": false, "cwd": " workspaceFolder/main.exe","args":[],"stopAtEntry":false,"cwd":"{workspaceFolder}”,
“environment”: [],
“externalConsole”: true,
“MIMode”: “gdb”,
“miDebuggerPath”: “C:\cygwin64\bin\gdb.exe”,
“setupCommands”: [
{
“description”: “Enable pretty-printing for gdb”,
“text”: “-enable-pretty-printing”,
“ignoreFailures”: true
}
]
}
]
}

VSCode + cygwin + cmake编译C/C++工程

  1. vscode 安装cmake 和cmake tool 。
  2. 编写 CMakeLists.txt
  3. 调用cmke, terminal中输入或者编写一个task调用

VSCode 的 优缺点

优点:代码提示好
缺点:不支持重命名的重构,不支持查找reference,截至20190328

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值