Install Clangd on CentOS 7
source link: https://jdhao.github.io/2021/07/03/install_clangd_on_linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Install Clangd on CentOS 7
Clangd is a language server for C++/C etc. On CentOS 7, I try to use clangd 12 for code auto-completion. Clangd can be easily installed via its binary release.
My failed attempt to use clang binary release
When I run clangd --version
, I see the following error:
clangd_12.0.0/bin/clangd: /lib64/libc.so.6: version `GLIBC_2.18' not found (required by clangd_12.0.0/bin/clangd)
The reason is that the shared library libc.so
is too old for clangd to run.
We need to use a newer version of glibc (at least glibc-2.18).
I tried to clone glibc and build version 2.20 from scratch:
git clone https://mirrors.tuna.tsinghua.edu.cn/git/glibc.git
cd glibc
git checkout glibc-2.20
cd ..
# Note that glibc requires out-source building, i.e., we are forbidden to build glibc inside its source directory.
mkdir glibc-build
../glibc/configure --prefix=$HOME/local
make -j 16
make install
I add $HOME/local/lib
to LD_LIBRARY_PATH
. Then things go badly wrong. Every
executable I use segfaults immediately. For example, when I use ls
, it will
print out:
zsh: segmentation fault (core dumped) ls -F –color=auto
According to this post, this is caused by version mismatch: the glibc version requried to run the executable is different from what is provided right now.
I tried the glibc-6.18 release tar downloaed from here. The same errors happens when I add
$HOME/local/lib
to LD_LIBRARY_PATH
and run clang
.
Build clangd from source
Maybe we need to build llvm project to use clangd. Here is how to compile llvm from source:
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 project we want to build. To useclangd
andclang-tidy
,clang-tools-extra
is a must.-DCMAKE_INSTALL_PREFIX=~/tools/llvm
: it specifies where we want to install llvm.-DCMAKE_BUILD_TYPE=Release
: it specifies the build type.Release
type is smaller thanDebug
.
For more detail on Cmake options when building llvm, check here.
Since llvm is a huge project, it may take a long time to build. It takes 37m to build on my server with 16 concurrent processes.
After installing llvm, do not forget to add llvm binary to your PATH
variable.
Recommend
-
37
Introduction I’ve long been a fan of smart editors which have a semantic understanding of the code you’re editing, and leverage it to provide semantics-aware features such as accurate code completion (only offeri...
-
3
How to install OwnCloud 8 in CentOS 6 running on Parallels Plesk 12 with the MySQL database? advertisements The installation from Terminal wor...
-
62
配置nvim-lspconfig和clangd的注意事项 clangd可以通过homebrew安装 brew install llvm clangd一定要在PATH环境变量下,否则neovim找不到它,LSP也就不能生效。在Apple M1安装llvm后,它的路径在/o...
-
4
How to install Docker on CentOS paulwong My Links Blog Stats Posts - 1074 Stories - 10 Comments - 108 ...
-
14
Install Python 3.8 on CentOS 7In this guide, you’ll learn how to install Python 3.8 on CentOS 7 / CentOS 8. Python is a popular programming language originally created by Guido van Rossum, and released in 1991. Python can be used to create we...
-
1
Welcome to our guide on how to install MongoDB 4.2 on CentOS 7 / Fedora 31/30/29/28. MongoDB is an open source NoSQL database system written in C++. It is designed for high scalability, performance, and availability.Step 1: Update Sys...
-
3
V2EX › C++ 问个 vscode 里使用 .clangd 的问题 ifanze · 11 小时 8 分钟前 · 211...
-
7
Setting up VisualStudio code to work with WebKitGTK using clangd – Alicia's blog Skip to content...
-
6
vscode C++ 开发之使用 clangd、C/C++、clang-format ...
-
2
ClangdIntroductionclangd is a clang-based language server. It brings IDE features (e.g. diagnostics, code completion, co...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK