Monday, December 18, 2023

Build clangd from source

Copied from https://jdhao.github.io/2021/07/03/install_clangd_on_linux/ because sometimes good things disappear from the 'net.

quote

git clone --depth=1 https://github.com/llvm/llvm-project.git

cd llvm-project
mkdir build && cd build
cmake -G "Unix Makefiles" -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" -DCMAKE_INSTALL_PREFIX=~/tools/llvm -DCMAKE_BUILD_TYPE=Release ../llvm
make -j 16
make install

Some explanation about the options used:

  • -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra": it specifies which targets we want to build. To use clangd and clang-tidy, clang-tools-extra is a must.
  • -DCMAKE_INSTALL_PREFIX=~/tools/llvm: it specifies where we want to install llvm, in this case, we install it under ~/tools/llvm.
  • -DCMAKE_BUILD_TYPE=Release: it specifies the build type. Release type will be smaller than Debug.

For more details about Cmake options on building llvm, check here.

/quote

Thanks jdhao!

I need this because the work VMs use RHEL7 with no chance to upgrade (the project is built on this to support customers running RHEL7 and up), and I want to config neovim lsp with cpp support.

But wait there's more. This version of LLVM needs cmake 3.20 or higher and of course the VM only has cmake 2.8

- visit cmake.org/download and wget the source

- extract

./bootstrap --prefix=/usr/local
make -j8
sudo make install
 

And now GCC needs to be version 7.4 or newer, but the VM is running 4.8.5. Sigh.

 

No comments:

Post a Comment