VIM YouCompleteMe自动补全插件配置

YouCompleteMe插件

配置步骤

#编译支持 C++17 的 GCC

gcc源代码以ftp的形式发布,除了gnu官方的服务器外,在世界各地都有镜像站,国内靠谱的镜像站有阿里云等。

下载源码并解压:

这里使用9.4.0版

1
2
wget https://mirrors.aliyun.com/gnu/gcc/gcc-9.4.0/gcc-9.4.0.tar.gz
tar -zxf gcc-9.4.0.tar.gz

创建编译用的目录,我一般习惯命名为build:

1
mkdir build && cd build

编译配置:

此处可配置的选项极多,具体含义可以在gcc网站上查询. 如果不知道应该加什么参数,可以参考系统上已有的gcc的配置参数:gcc -v

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
../configure -v \
--prefix=/usr/local
--enable-languages=c,c++ \
--with-gcc-major-version-only \
--enable-shared \
--enable-linker-build-id \
--without-included-gettext \
--enable-threads=posix \
--enable-nls \
--enable-bootstrap \
--enable-clocale=gnu \
--enable-libstdcxx-debug \
--enable-libstdcxx-time=yes \
--with-default-libstdcxx-abi=new \
--enable-gnu-unique-object \
--disable-vtable-verify \
--enable-libmpx \
--enable-plugin \
--enable-default-pie \
--with-system-zlib \
--with-target-system-zlib \
--enable-multiarch \
--disable-werror \
--with-arch-32=i686 \
--with-abi=m64 \
--with-multilib-list=m32,m64,mx32 \
--enable-multilib \
--with-tune=generic \
--enable-offload-targets=nvptx-none \
--without-cuda-driver \
--enable-checking=release \
--build=x86_64-linux-gnu \
--host=x86_64-linux-gnu \
--target=x86_64-linux-gnu

此处解释几个关键配置

  • –build

    当前正在使用的机器的环境

  • –host

    编译产物(gcc)将会运行在的环境

  • –target

    编译出来的gcc的编译产物的目标环境

以上三个参数用于交叉编译,比如在x86_64机器上(build)编译一个即将在arm上运行(host)的编译器,该编译器产生在arm上(target)运行的程序。三个参数的格式均为cpu-company-system

  • –prefix=/usr/local

    编译产物的安装目录。系统默认的gcc一般会安装在/usr下,为了不影响系统的gcc,建议设置为不同的路径

  • –enable-languages

    配置gcc支持的语言类型,可选项有ada, c, c++, go等, 由于笔者只需要c和c++,因此只开启了c和c++.

  • –enable-multilib

    是否编译target上的multilib, multilib是在target上编译和运行架构不同程序所需的库,比如在x86_64上编译运行32位程序。

  • –with-multilib-list

    开启的multilib列表,对于不同target,此处允许的值有所不同。在x86_64-*-linux*上有m32, m64, mx32三个可选项。

开始编译并安装:

1
2
make
sudo make install

环境变量配置:

下面的$INSTALLDIR要换成对应的值。

1
2
3
4
echo export PATH="$INSTALLDIR/bin:\$PATH" >> $HOME/.bashrc
echo export CPPFLAGS="-I$INSTALLDIR/include \$CPPFLAGS" >> $HOME/.bashrc
echo export LDFLAGS="-L$INSTALLDIR/lib64 -L$INSTALLDIR/lib \$LDFLAGS" >> $HOME/.bashrc
echo export LD_LIBRARY_PATH="$INSTALLDIR/lib64:$INSTALLDIR/lib:\$LD_LIBRARY_PATH" >> $HOME/.bashrc

#安装 Python 3

YouCompleteMe需要最低Python3.6的环境,如果不满足,则需要安装

如果软件源中包含了满足要求的python版本,则可以直接安装;否则需要从源码编译。

a. 直接从软件源安装

1
sudo apt install python3.8 python3.8-dev

b. 从源码编译Python3

暂时没有用到,略过

#编译 VIM

VIM的编译过程相对简单了很多

克隆代码,可以直接克隆最新版本:

1
git clone --depth 1 https://github.com/vim/vim.git    

编译配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cd vim/src
./configure \
--with-features=huge \
--enable-multibyte \
--enable-pythoninterp=dynamic \
--with-python-config-dir=$(python2.7-config --configdir) \
--enable-python3interp=dynamic \
--with-python3-config-dir=$(python3.8-config --configdir) \
--enable-cscope \
--enable-gui=auto \
--enable-gtk2-check \
--enable-fontset \
--enable-largefile \
--disable-netbeans \
--with-compiledby="xxxxx@xx.com" \
--enable-fail-if-missing

编译安装:

1
2
make
sudo make install

#安装 CMAKE

下载cmake并安装:

1
2
3
wget https://github.com/Kitware/CMake/releases/download/v3.21.3/cmake-3.21.3-linux-x86_64.sh
chmod +x cmake-3.21.3-linux-x86_64.sh
./cmake-3.21.3-linux-x86_64.sh

配置环境变量:

1
echo export PATH=$(pwd)/cmake-3.21.3-linux-x86_64/bin:\$PATH >> $HOME/.bashrc  

#安装 YouCompleteMe 插件

——待更新