0

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?

Rorschach
  • 31,301
  • 5
  • 78
  • 129
eager2learn
  • 1,447
  • 4
  • 24
  • 47
  • How exactly have you "added its path as an environment variable" – mmmmmm Sep 05 '19 at 11:49
  • Added 'export PATH=/usr/local/opt/llvm/bin:$PATH' to my .bash_profile file. – eager2learn Sep 05 '19 at 13:19
  • 1
    Look at `exec-path` and `(getenv "PATH")` in Emacs. If they don't have your directory, then you're not adding it in a way that Emacs is seeing it. You can simply add it to `exec-path` and it will probably work (`exec-path` is initialized from `$PATH` at start up; usually `$PATH` isn't used after start up in Emacs). – jpkotta Sep 05 '19 at 15:34
  • I got this to work today on Linux (Debian 10). In my emacs file I had to add: (setq lsp-clients-clangd-executable "/usr/lib/llvm-9/bin/clangd"). Maybe you need to do something like that. – snow_abstraction Sep 14 '19 at 19:37
  • I recommend confirming that you've got clangd. – snow_abstraction Sep 14 '19 at 19:39
  • Windows, Linux or MacOS? It matters. In Linux/MacOS typing `which clang` returns the full path of the executable, in CMD you must use `where` and `Get-Command` in PowerShell. – Daniele Jan 31 '21 at 20:06

1 Answers1

1

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