Linux之CentOS 6编译安装vim添加Lua、Perl、Ruby、Python的支持和YouCompleteMe自动补全功能

摘要

YouCompleteMe:一个随键而全的、支持模糊搜索的、高速补全的插件。YCM 由 google 公司搜索项目组的软件工程师 Strahinja Val Markovic 所开发,YCM 后端调用 libclang(以获取AST,当然还有其他语言的语义分析库)、前端由 C++ 开发(以提升补全效 率)、外层由 python 封装(以成为 vim 插件),它可能是我见过安装最复杂的 vim 插件了。

编译安装Python2.7.10

[[email protected] ~]# yum install readline-devel sqlite-devel -y
[[email protected] ~]# wget -c http://www.dwhd.org/script/tar_gz_bz2/Python-2.7.10.tar.xz
[[email protected] ~]# tar xf Python-2.7.10.tar.xz
[[email protected] ~]# cd Python-2.7.10/
[[email protected] ~/Python-2.7.10]# ./configure --prefix=/usr/local/python2.7.10
[[email protected] ~/Python-2.7.10]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ..
[[email protected] ~]# /usr/local/python2.7.10/bin/python --version
Python 2.7.10
[[email protected] ~]# 

为什么编译高版本python的原因
Linux之CentOS 6编译安装vim添加Lua、Perl、Ruby、Python的支持和YouCompleteMe自动补全功能

安装Lua

[[email protected] ~]# yum -y install lua lua-devel
[[email protected] ~]# wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz
[[email protected] ~]# tar -xzvf LuaJIT-2.0.4.tar.gz
[[email protected] ~/LuaJIT-2.0.4]# cd LuaJIT-2.0.4
[[email protected] ~/LuaJIT-2.0.4]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` && make install && cd ..

编译VIM7.4
确保Vim版本至少是7.3.584,并且支持python2脚本。

[[email protected] ~]# yum -y install python-devel ruby ruby-devel perl perl-devel perl-ExtUtils-Embed
git clone https://github.com/vim/vim.git
[[email protected] ~]# cd vim
[[email protected] ~/vim]# ./configure --prefix=/usr/local/vim7.4 --disable-selinux --enable-luainterp=yes --enable-fail-if-missing --enable-perlinterp --enable-pythoninterp --enable-rubyinterp --enable-cscope --enable-gui=auto --enable-gtk2-check --enable-gnome-check --with-features=huge --with-luajit --with-x --with-python-config-dir=/usr/lib64/python2.6/config/
##/usr/lib64/python2.6/config/这个路径是根据系统位数来确定的。
[[email protected] ~/vim]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` && make install && cd ..
[[email protected] ~]# ln -sv /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
[[email protected] ~]# echo "export PATH=/usr/local/vim7.4/bin:\$PATH" > /etc/profile.d/vim74.sh
[[email protected] ~]# sed -i "$(awk '$1=="MANPATH"{i=NR}END{print i}' /etc/man.config)a \MANPATH\tMANPATH /usr/local/vim7.4/share/man" /etc/man.config

检查VIM

[[email protected] ~]# vim --version|grep -Eo '\+(python|ruby|perl|lua)'
+perl
+python
+lua
+ruby
[[email protected] ~]# vim --version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Oct  4 2015 14:19:47)
包含补丁: 1-889
编译者 [email protected]
巨型版本 无图形界面。  可使用(+)与不可使用(-)的功能:
+acl             +farsi           +mouse_netterm   +syntax
+arabic          +file_in_path    +mouse_sgr       +tag_binary
+autocmd         +find_in_path    -mouse_sysmouse  +tag_old_static
-balloon_eval    +float           +mouse_urxvt     -tag_any_white
-browse          +folding         +mouse_xterm     -tcl
++builtin_terms  -footer          +multi_byte      +terminfo
+byte_offset     +fork()          +multi_lang      +termresponse
+cindent         +gettext         -mzscheme        +textobjects
-clientserver    -hangul_input    +netbeans_intg   +title
-clipboard       +iconv           +path_extra      -toolbar
+cmdline_compl   +insert_expand   +perl            +user_commands
+cmdline_hist    +jumplist        +persistent_undo +vertsplit
+cmdline_info    +keymap          +postscript      +virtualedit
+comments        +langmap         +printer         +visual
+conceal         +libcall         +profile         +visualextra
+cryptv          +linebreak       +python          +viminfo
+cscope          +lispindent      -python3         +vreplace
+cursorbind      +listcmds        +quickfix        +wildignore
+cursorshape     +localmap        +reltime         +wildmenu
+dialog_con      +lua             +rightleft       +windows
+diff            +menu            +ruby            +writebackup
+digraphs        +mksession       +scrollbind      -X11
-dnd             +modify_fname    +signs           -xfontset
-ebcdic          +mouse           +smartindent     -xim
+emacs_tags      -mouseshape      -sniff           -xsmp
+eval            +mouse_dec       +startuptime     -xterm_clipboard
+ex_extra        -mouse_gpm       +statusline      -xterm_save
+extra_search    -mouse_jsbterm   -sun_workshop    -xpm
     系统 vimrc 文件: "$VIM/vimrc"
     用户 vimrc 文件: "$HOME/.vimrc"
 第二用户 vimrc 文件: "~/.vim/vimrc"
      用户 exrc 文件: "$HOME/.exrc"
         $VIM 预设值: "/usr/local/vim7.4/share/vim"
编译方式: gcc -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1       
链接方式: gcc   -L.  -rdynamic -Wl,-export-dynamic -Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl   -liconv -ldl  -L/usr/lib -lluajit-5.1 -Wl,-E -Wl,-rpath,/usr/lib64/perl5/CORE  -fstack-protector  -L/usr/lib64/perl5/CORE -lperl -lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc -L/usr/lib64/python2.6/config/ -lpython2.6 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic   -lruby -lpthread -lrt -ldl -lcrypt -lm 

编译高级版本gcc (重量级编译耗时很长)

[[email protected] ~]# wget http://mirrors.dwhd.org/GCC/releases/gcc-4.9.3/gcc-4.9.3.tar.bz2
[[email protected] ~]# tar xf gcc-4.9.3.tar.bz2 
[[email protected] ~]# cd gcc-4.9.3/
[[email protected] ~/gcc-4.9.3]# ./contrib/download_prerequisites
[[email protected] ~/gcc-4.9.3]# mkdir gcc-4.9.3 && cd gcc-4.9.3
[[email protected] ~/gcc-4.9.3/gcc-4.9.3]# ../configure --prefix=/usr -enable-checking=release -enable-languages=c,c++ -disable-multilib
[[email protected] ~/gcc-4.9.3/gcc-4.9.3]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` && make install && cd ../..
[[email protected] ~]# . /etc/profile
[[email protected] ~]# . ~/.bash_profile
[[email protected] ~]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-unknown-linux-gnu/4.9.3/lto-wrapper
目标:x86_64-unknown-linux-gnu
配置为:../configure -enable-checking=release -enable-languages=c,c++ -disable-multilib
线程模型:posix
gcc 版本 4.9.3 (GCC) 
[[email protected] ~]# 

你以为我想编译高版本gcc吗?我也是被逼的好不好。。。
Linux之CentOS 6编译安装vim添加Lua、Perl、Ruby、Python的支持和YouCompleteMe自动补全功能

编译安装clang (重量级编译耗时很长)
Clang是一个开源编译器,能够编译C/C++/Objective-C/Objective-C++。Clang提供的libclang库是用于驱动YCM对这些语言的语义补全支持。YCM需要版本至少为3.6的libclang,但是理论上3.2+版本也行。也可以使用系统libclang,如果确定是3.3版本或者更高。推荐下载官网的二进制文件。确保选对适合自己系统的包。

[[email protected] ~]# cd ~/
[[email protected] ~]# wget -c http://www.dwhd.org/wp-content/uploads/2015/10/llvm-clang.tar.gz
[[email protected] ~]# tar xf llvm-clang.tar.gz
[[email protected] ~]# mkdir ~/llvm-clang/llvm-build && cd ~/llvm-clang/llvm-build
[[email protected] ~/llvm-clang/llvm-build]# ../llvm/configure --enable-optimized --enable-targets=host-only --with-python=/usr/local/python2.7.10/bin/python
[[email protected] ~/llvm-clang/llvm-build]# make -j `awk '/processor/{a++}END{print a}' /proc/cpuinfo` && make install && cd ../..
[[email protected] ~]# clang -v
clang version 3.8.0 (trunk 249283)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.4
Found candidate GCC installation: /usr/lib/gcc/x86_64-redhat-linux/4.4.7
Found candidate GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.3
Selected GCC installation: /usr/local/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.3
Candidate multilib: .;@m64
Selected multilib: .;@m64
[[email protected] ~]#

安装clang标准库

##安装libc++
[[email protected] ~]# cd ~/llvm-clang
[[email protected] ~/llvm-clang]# svn co http://llvm.org/svn/llvm-project/libcxx/trunk libcxx
[[email protected] ~/llvm-clang]# cd libcxx/lib
[[email protected] ~/llvm-clang/libcxx/lib]# ./buildit
###头文件已经生成到 ~/llvm-clang/libcxx/include/,要让 clang 找到必须复制到 /usr/include/c++/v1/
[[email protected] ~/llvm-clang/libcxx/lib]# cp -r ~/llvm-clang/libcxx/include/ /usr/include/c++/v1/
###*.so 文件已生成 ~/llvm-clang/libcxx/lib/libc++.so.1.0,要让 clang 访问必须复 制到 /usr/lib/,并创建软链接
[[email protected] ~/llvm-clang/libcxx/lib]# ln -s ~/llvm-clang/libcxx/lib/libc++.so.1.0 ~/llvm-clang/libcxx/lib/libc++.so.1
[[email protected] ~/llvm-clang/libcxx/lib]# ln -s ~/llvm-clang/libcxx/lib/libc++.so.1.0 ~/llvm-clang/libcxx/lib/libc++.so
ln: 创建符号链接 "/root/llvm-clang/libcxx/lib/libc++.so": 文件已存在
[[email protected] ~/llvm-clang/libcxx/lib]# cp ~/llvm-clang/libcxx/lib/libc++.so* /usr/lib/
cp:是否覆盖"/usr/lib/libc++.so"? yes
cp:是否覆盖"/usr/lib/libc++.so.1"? yes
cp:是否覆盖"/usr/lib/libc++.so.1.0"? yes

##类似,源码安装 libc++abi 的头文件和动态链接库:
[[email protected] ~/llvm-clang/libcxx/lib]# cd  ~/llvm-clang/
[[email protected] ~/llvm-clang]# svn co http://llvm.org/svn/llvm-project/libcxxabi/trunk libcxxabi
[[email protected] ~/llvm-clang]# cd libcxxabi/lib
[[email protected] ~/llvm-clang/libcxxabi/lib]# ./buildit
###头文件已经生成到 ~/llvm-clang/libcxxabi/include/,要让 clang 找到必须复制到 /usr/include/c++/v1/
[[email protected] ~/llvm-clang/libcxxabi/lib]# cp -r ~/llvm-clang/libcxxabi/include/ /usr/include/c++/v1/
###*.so 文件已生成 ~/llvm-clang/libcxx/lib/libc++abi.so.1.0,要让 clang 访问必 须复制到 /usr/lib/,并创建软链接
[[email protected] ~/llvm-clang/libcxxabi/lib]# ln -s ~/llvm-clang/libcxxabi/lib/libc++abi.so.1.0 ~/llvm-clang/libcxxabi/lib/libc++abi.so.1
[[email protected] ~/llvm-clang/libcxxabi/lib]# ln -s ~/llvm-clang/libcxxabi/lib/libc++abi.so.1.0 ~/llvm-clang/libcxxabi/lib/libc++abi.so
[[email protected] ~/llvm-clang/libcxxabi/lib]# cp ~/llvm-clang/libcxxabi/lib/libc++abi.so* /usr/lib/

安装vundle

[[email protected] ~]# mkdir ~/.vim/bundle/
[[email protected] ~]# git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
###在.vimrc 中添加bundle的配置
[[email protected] ~]# cat .vimrc
set nocompatible                " be iMproved
filetype off                    " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()

" let Vundle manage Vundle
Bundle 'gmarik/vundle'

"my Bundle here:
"
" original repos on github
Bundle 'kien/ctrlp.vim'
Bundle 'sukima/xmledit'
Bundle 'sjl/gundo.vim'
Bundle 'jiangmiao/auto-pairs'
Bundle 'klen/python-mode'
Bundle 'Valloric/ListToggle'
Bundle 'SirVer/ultisnips'
"Bundle 'Valloric/YouCompleteMe'
Bundle 'scrooloose/syntastic'
Bundle 't9md/vim-quickhl'
"Bundle 'Lokaltog/vim-powerline'
Bundle 'scrooloose/nerdcommenter'
"..................................
" vim-scripts repos
Bundle 'YankRing.vim'
Bundle 'vcscommand.vim'
Bundle 'ShowPairs'
Bundle 'SudoEdit.vim'
Bundle 'EasyGrep'
Bundle 'VOoM'
Bundle 'VimIM'
"..................................
" non github repos
" Bundle 'git://git.wincent.com/command-t.git'
"......................................
filetype plugin indent on
###然后执行
[[email protected] ~]# vim +BundleInstall +qall

Linux之CentOS 6编译安装vim添加Lua、Perl、Ruby、Python的支持和YouCompleteMe自动补全功能

安装YouCompleteMe

[[email protected] ~]# \rm -rf ~/.vim/bundle/YouCompleteMe
[[email protected] ~]# git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
[[email protected] ~]# cd ~/.vim/bundle/YouCompleteMe
[[email protected] ~/.vim/bundle/YouCompleteMe]# git submodule update --init --recursive
[[email protected] ~/.vim/bundle/YouCompleteMe]# ./install.sh --clang-completer

===========下面的不用看,博主卡在这里了==============

[[email protected] ~]# mkdir -pv ~/.vim/bundle && cd ~/.vim/bundle
[[email protected] ~]# git clone https://github.com/gmarik/vundle.git ~/.vim/bundle/vundle
[[email protected] ~]# echo "filetype off
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
Bundle 'Valloric/YouCompleteMe'
filetype plugin indent on" >>/etc/vimrc
[[email protected] ~]# git clone https://github.com/Valloric/YouCompleteMe.git ~/.vim/bundle/YouCompleteMe
[[email protected] ~]# cd ~/.vim/bundle/YouCompleteMe/
[[[email protected] ~/.vim/bundle/YouCompleteMe]# git submodule update --init --recursive && cd ~/


[[email protected] ~/llvm-clang]# svn co http://llvm.org/svn/llvm-project/llvm/trunk llvm
[[email protected] ~/llvm-clang/llvm]# cd llvm/tools
[[email protected] ~/llvm-clang/llvm/tools]# svn co http://llvm.org/svn/llvm-project/cfe/trunk clang
[[email protected] ~/llvm-clang/llvm/tools]# cd ../..
[[email protected] ~/llvm-clang]# cd llvm/tools/clang/tools
[[email protected] ~/llvm-clang/llvm/tools/clang/tools]# svn co http://llvm.org/svn/llvm-project/clang-tools-extra/trunk extra
[[email protected] ~/llvm-clang/llvm/tools/clang/tools]# cd ../../../.. && cd llvm/projects
[[email protected] ~/llvm-clang/llvm/projects]# svn co http://llvm.org/svn/llvm-project/compiler-rt/trunk compiler-rt
[[email protected] ~/llvm-clang/llvm/projects]# cd ../..
[[email protected] ~/llvm-clang]# mkdir llvm-build && cd llvm-build/

[[email protected] ~]# tar xf cfe-3.*.src.tar.xz
[[email protected] ~]# mkdir ycm_build
[[email protected] ~]# cd ycm_build
[[email protected] ~/ycm_build]# cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
[[email protected] ~/ycm_build]# cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/llvm-3.7.0.src . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
[[email protected] ~/ycm_build]#

稍后整理

  • 本文由 发表于 2015年10月4日13:36:37
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: