Ubuntu22,VS Code下C++代码审查工具:Clang Command Adapter

17 篇文章 1 订阅

1.安装 Clang: 

sudo apt update
sudo apt-get install clang

2.安装 “C/C++ Clang Command Adapter 插件

在 VS Code 中,打开扩展视图(点击侧边栏的扩展图标或使用快捷键 Ctrl+Shift+X),搜索并安装官方的 "C/C++ Clang Command Adapter " 扩展。

3.配置 c_cpp_properties.json:

 指定 Clang 作为编译器。通常,这个文件位于 .vscode 文件夹中,并且可以通过命令面板(Ctrl+Shift+P)中的 "C/C++: Edit Configurations (JSON)" 命令来编辑。

{
    "configurations": [
        {
            "name": "Ubuntu",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 1
}

请确保 "compilerPath" 指向正确的 Clang 可执行文件路径。在大多数 Linux 发行版中,Clang 的默认安装路径是 /usr/bin/clang

4.配置 tasks.json

如果需要自定义构建任务,可以编辑 tasks.json 文件。这个文件也位于 .vscode 文件夹中,可以通过命令面板中的 "Tasks: Configure Task" 命令来创建或编辑。

tasks.json 文件中,你可以定义一个任务来使用 Clang 编译你的项目:

{
    "version": "1.0.0",
    "tasks": [
        {
            "label": "build clang",
            "type": "shell",
            "command": "clang",
            "args": ["-Wall", "${file}"],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

5.配置 launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Clang Build and Debug",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/your_program",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "build clang"
        }
    ]
}

VS Code 的 C/C++ 扩展使用 LLVM Clangd 提供智能感知功能,而 Clang Command Adapter 允许你使用 Clang 作为编译器和调试器。确保你安装了最新版本的 Clang,以获得最佳支持。

Alt+Shift+f 来格式化你的代码,把代码风格统一。 

 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值