Skip to content

Clangd

clangd understands your C++ code and adds smart features to your editor: code completion, compile errors, go-to-definition and more.

clangd is a language server that can work with many editors via a plugin.

clangd is based on the Clang C++ compiler, and is part of the LLVM project.

How to install

macOS

$ brew install llvm

출력은 다음과 같다:

==> Downloading https://homebrew.bintray.com/bottles/llvm-10.0.1.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/e3ec9fda84756750ac0b5620ff34da04ba5035c8276af1bebfe76e012bb0b14a?response-content-disposition=attachment%3Bfilename%3D%22llvm-10.0.1.catalina.bott
######################################################################## 100.0%
==> Pouring llvm-10.0.1.catalina.bottle.tar.gz
==> Caveats
To use the bundled libc++ please add the following LDFLAGS:
  LDFLAGS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib"

llvm is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have llvm first in your PATH run:
  echo 'export PATH="/usr/local/opt/llvm/bin:$PATH"' >> ~/.profile

For compilers to find llvm you may need to set:
  export LDFLAGS="-L/usr/local/opt/llvm/lib"
  export CPPFLAGS="-I/usr/local/opt/llvm/include"

==> Summary
🍺  /usr/local/Cellar/llvm/10.0.1: 7,029 files, 1GB

설치된 실행하일은 위에 적힌대로 PATH 경로에 /usr/local/opt/llvm/bin를 추가하거나 필요한 파일만 별도로 심볼릭 링크를 걸면 된다.

$ ln -s /usr/local/opt/llvm/bin/clangd clangd

Project setup

If your project builds with CMake, it can generate this file. You should enable it with:

cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=1 ...

compile_commands.json will be written to your build directory. If your build directory is $SRC or $SRC/build, clangd will find it. Otherwise, symlink or copy it to $SRC, the root of your source tree.

ln -s ~/myproject-build/compile_commands.json ~/myproject/

See also

Favorite site