【问题标题】:clang format not working in vscode linux ubuntuclang 格式在 vscode linux ubuntu 中不起作用
【发布时间】:2017-03-13 04:25:01
【问题描述】:

在 Ubuntu 中运行的 VSCode 中安装 clang-format 后,尝试调用它会给出错误可执行文件未找到;请配置clang-executable。 Clang 格式在 ' /home/alex/.vscode/extensions/ms-vscode.cpptools-0.10.3/LLVM/bin/clang 下可用 -格式'

【问题讨论】:

    标签: visual-studio-code clang-format


    【解决方案1】:

    我遇到了相同症状的不同问题。 为了能见度,我会在这里回答。

    系统/设置:

    • Ubuntu 20.04.1 LTS
    • Visual Studio 1.51.1
    • VS 扩展:Xaver 的 Clang-formatter v1.9.0

    安装externsion后它无法正常工作。当我查看主文件夹中的扩展文件夹时

    ~/.vscode/extensions/xaver*
    
    xaver.clang-format-1.9.0/
    ├── CHANGELOG.md
    ├── clang-format.png
    ├── LICENSE.txt
    ├── node_modules
    │   └── sax
    │       ├── lib
    │       │   └── sax.js
    │       ├── LICENSE
    │       ├── package.json
    │       └── README.md
    ├── out
    │   └── src
    │       ├── clangMode.js
    │       ├── clangPath.js
    │       └── extension.js
    ├── package.json
    ├── package-lock.json
    ├── README.md
    ├── tslint.json
    └── typings.json
    

    由于没有 bin 文件,我单独安装了 clang:

    sudo apt install clang-format
    

    此安装后,Visual Studio 中的扩展开始工作。

    【讨论】:

    • 附注,在 Ubuntu 18.04 上 sudo apt-get install clang-formatter 抱怨“E:无法找到包 clang-formatter。”
    • @LouisGo 试试sudo apt-get install clang-format
    【解决方案2】:

    即使我尝试配置 vscode setting.json 也没有成功。然后从http://www.codepool.biz/vscode-format-c-code-windows-linux.html 获取信息并创建到目标的链接

    sudo ln -s /home/alex/.vscode/extensions/ms-vscode.cpptools-0.10.3/LLV
    M/bin/clang-format /usr/bin/clang-format
    

    【讨论】:

      【解决方案3】:

      你需要运行

      sudo apt-get install clang-format
      

      那么它应该可以工作了!

      然后尝试使用 Clang 格式 Ctrl+Shift+i

      享受吧!

      【讨论】: