emacs lsp c-mode: Command "clangd" is not present on the path

2.6k Views Asked by At

I want to use Emacs LSP c-mode, but I'm getting the error 'Command "clangd" is not present on the path'.

I did the following steps to install:

  1. Get lsp package from melpa-stable
  2. Get company-lsp from melpa-stable
  3. Get ccls using homebrew
  4. Add the following to my .emacs file:

    (require 'lsp-mode) (add-hook 'rust-mode-hook #'lsp) (add-hook 'c-mode-hook #'lsp) (require 'company-lsp) (push 'company-lsp company-backends)

I have installed llvm (which should include clang) using homebrew and added its path as an environment variable.

Does anybody know why I get this error?

1

There are 1 best solutions below

0
On

I have just managed to set it up.

The problem is that on os x your environmental variables are not imported correctly when using GUI emacs. In particular, if you try evaluating in your emacs

(getenv "PATH")

you will get a different output from what you get by running

echo $PATH

in your terminal.

I have solved this by installing exec-path-from-shell as suggested here.

Finally, double check (even though you've mentioned, you've done this) that not only have you installed llvm, but also correctly added it to your path, by running

brew install llvm
ln -s "$(brew --prefix llvm)/bin/clangd" "/usr/local/bin/clangd"

as suggested here