简体   繁体   English

如何在 Mac 上安装 clangd?

[英]How to install clangd on Mac?

I am trying to use clangd with Spacemacs according to the c-cpp page.我正在尝试根据c-cpp页面将clangd与 Spacemacs 一起使用。 I have tried downloading the macOS binary for LLVM and I have followedthis and this , but when I run which clangd , it says it cannot be found.我曾尝试为 LLVM 下载 macOS 二进制文件,并且我遵循了thisthis ,但是当我运行which clangd ,它说找不到它。 I have also run brew install llvm , but that also doesn't show that clangd is in my path.我也运行了brew install llvm ,但这也没有表明clangd在我的路径中。 I do have a binary under /usr/local/Cellar/llvm/9.0.0_1/bin , but my LSP doesn't do anything when I restart Emacs and open a C++ source file.我在/usr/local/Cellar/llvm/9.0.0_1/bin下确实有一个二进制文件,但是当我重新启动 Emacs 并打开 C++ 源文件时,我的 LSP 没有做任何事情。 I have /usr/local/bin in my path.我的路径中有/usr/local/bin

I added /usr/local/opt/llvm/bin/ to my PATH and that worked.我将/usr/local/opt/llvm/bin/到我的 PATH 并且有效。 Thanks to Mikael Springer .感谢Mikael Springer I wonder why it wasn't working with the other location (and why I have multiple copies of llvm binaries).我想知道为什么它不能与其他位置一起使用(以及为什么我有 llvm 二进制文件的多个副本)。

I have the following in my init.el with Emacs, not Spacemacs;我的 init.el 中有 Emacs,而不是 Spacemacs;

(use-package lsp-clients
    :config
    (setq lsp-clients-clangd-executable "/usr/local/opt/llvm/bin/clangd")
    (setq lsp-clients-clangd-args '("-j=4" "-background-index" "-log=info" "-pretty" "-resource-dir=/Applications/Xcode9.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/9.0.0")))

As you can see I use use-package for Emacs package management but the important part is setting the lsp-clients-clangd-* variables.如您所见,我使用use-package进行 Emacs 包管理,但重要的部分是设置 lsp-clients-clangd-* 变量。 I install LLVM (and clangd) using brew install llvm .我使用brew install llvm安装 LLVM(和 clangd)。 I don't know how or if this might help you since you use Spacemacs and I am not familiar with configuring Spacemacs.我不知道这如何或是否对您有帮助,因为您使用 Spacemacs,而我不熟悉配置 Spacemacs。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM