Skip to content

Instantly share code, notes, and snippets.

@tgroshon
Last active March 29, 2022 14:36
Show Gist options
  • Save tgroshon/804899746febd1cf175d1a42c9d7cd4e to your computer and use it in GitHub Desktop.
Save tgroshon/804899746febd1cf175d1a42c9d7cd4e to your computer and use it in GitHub Desktop.
Spacemacs LSP for C++

Setting up Spacemacs for C/C++ Dev

Install CCLS

See included install-ccls.sh.

  1. Install dependencies: sudo apt install clang-9 libclang-9-dev rapidjson-dev zlib1g-dev libncurses-dev
  2. Download archived CCLS source from github release page: Releases-MaskRay/ccls
  3. Unarchive: tar -xzf ccls-0.20210330.tar.gz
  4. CMake build: cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/lib/llvm-9 -DLLVM_INCLUDE_DIR=/usr/lib/llvm-9/include -DLLVM_BUILD_INCLUDE_DIR=/usr/include/llvm-9/
  5. CMake install: sudo cmake --build Release

Enable appropriate configuration layers

(c-c++ :variables c-c++-backend 'lsp-ccls)
cmake
lsp

Create Compilation Database (compile_commands.json) for C/C++ Project

If using CMake, add -DCMAKE_EXPORT_COMPILE_COMMANDS=1 to your cmake build command and then copy the resulting compile_commands.json file from the build directory to your source or project directory.

If using Make directly, use a tool like Bear: bear make or bear make build

#!/bin/bash
sudo apt install clang-9 libclang-9-dev rapidjson-dev zlib1g-dev libncurses-dev
pushd ~/Downloads
wget https://github.com/MaskRay/ccls/archive/refs/tags/0.20210330.tar.gz -O ./ccls-0.20210330.tar.gz
tar -xzf ccls-0.20210330.tar.gz
pushd ccls-0.20210330
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/lib/llvm-9 -DLLVM_INCLUDE_DIR=/usr/lib/llvm-9/include -DLLVM_BUILD_INCLUDE_DIR=/usr/include/llvm-9/
sudo cmake --build Release --target install
popd # out of ccls source directory
popd # out of ~/Downloads directory
(setq-default
dotspacemacs-configuration-layers
'(
(c-c++ :variables c-c++-backend 'lsp-ccls)
cmake
lsp
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment