搭建vim开发环境

一、安装llvm+clang工具

这里通过apt进行自动化安装时,llvm和clang工具不会被全部安装,存在很多问题。所以一定要手动编译源码安装。
安装过程分成三步:拉取llvm及clang源码、配置及编译、安装

拉取llvm及clang源码

llvm是开源编译框架,clang是llvm的子项目。在github上有llvm工程可以拉取,同时拉取子模块,就一步到位了,省去指定各个部分的目录。

cd ~/Download
git clone --recursive https://github.com/llvm/llvm-project.git

之后是漫长的等待,国内github访问极慢,基本拉取不成功,那么这里给出备份计划。
我们从gitee网站拉取llvm的国内镜像,速度贼快。

cd ~/Download
git clone --recursive https://gitee.com/mirrors/LLVM.git

这时候源码很快拉下来了。

配置和编译

配置过程读一下llvm的readme就可以了,写的相当简单方便,但是安装过程绝对没有这么简单。
配置过程可以参考下面配置命令,太繁琐,当然可以直接跳过,看配置命令就好。

配置过程解释

cd llvm-project

mkdir build

cd build

cmake -G [options] …/llvm

Some common build system generators are:

Ninja --- for generating Ninja build files. Most llvm developers use Ninja.
Unix Makefiles --- for generating make-compatible parallel makefiles.
Visual Studio --- for generating Visual Studio projects and solutions.
Xcode --- for generating Xcode projects.

Some Common options:

-DLLVM_ENABLE_PROJECTS='...' --- semicolon-separated list of the LLVM sub-projects you'd like to additionally build. Can include any of: clang, clang-tools-extra, libcxx, libcxxabi, libunwind, lldb, compiler-rt, lld, polly, or debuginfo-tests.

For example, to build LLVM, Clang, libcxx, and libcxxabi, use -DLLVM_ENABLE_PROJECTS="clang;libcxx;libcxxabi".

-DCMAKE_INSTALL_PREFIX=directory --- Specify for directory the full path name of where you want the LLVM tools and libraries to be installed (default /usr/local).

-DCMAKE_BUILD_TYPE=type --- Valid options for type are Debug, Release, RelWithDebInfo, and MinSizeRel. Default is Debug.

-DLLVM_ENABLE_ASSERTIONS=On --- Compile with assertion checks enabled (default is Yes for Debug builds, No for all other build types).

配置命令

创建build目录,在build目录下进行配置和编译。

cd llvm-project 或者 cd LLVM(gitee仓库)
mkdir build
cd build

采用cmake进行安装,先安装cmake:

sudo apt install cmake

生成makefile:

cmake -G "Unix Makefiles" -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi"  -DCMAKE_BUILD_TYPE="Release" ../llvm-project/llvm/

这里强调一点,gcc 和g++事先安装好。
Release,不要安装debug。
我尝试了debug安装,86%时候占用了80G硬盘,10G内存,30G swap空间,分分钟卡死在那。

增加swap空间50G

dd if=/dev/zero of=/data2/swapfile bs=1M count=50240
mkswap swapfile
swapon swapfile

编译

sudo make -j4

安装

sudo make install

vim源码编译安装

拉取源码

cd ~/Download
git clone --recursive https://github.com/vim/vim.git

安装依赖

sudo apt-get install libncurses5-dev libgnome2-dev libgnomeui-dev libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev python-dev ruby-dev mercurial

安装python3 python3-dev python python-dev
使用系统剪贴板,安装libxt-dev

配置与安装

./configure --with-x --with-features=huge --enable-python3interp --with-python3-config-dir=/usr/lib/python3.10/config-3.10-x86_64-linux-gnu/ --enable-rubyinterp --enable-luainterp --enable-perlinterp  --enable-multibyte --enable-cscope --enable-gui=gtk2

一定要修改python config文件目录为本机的目录。
安装如下:

sudo make -j4
sudo make install

安装vim插件及配置过程

参考git:
https://github.com/yangyangwithgnu/use_vim_as_ide

安装youcompleteme

这里优先采用clangd作为语言处理引擎,异步补全方式,丝滑流畅。

安装 使用lsp server clangd

cd .vim/bundle/YouCompleteMe
./install.py --clangd-completer
Logo

瓜分20万奖金 获得内推名额 丰厚实物奖励 易参与易上手

更多推荐