CentOS中安装YouCompleteMe插件详解

runningo 2017-10-19

本人在CentOS6.9和CentOS7中安装测试过YouCompleteMe插件,均无问题。整个安装步骤如下:(写的比较粗糙)

1,

win10 x64 : 通过无线网卡连接网络:
    IP: 192.168.1.106
    Netmast: 255.255.255.0
    gateway: 192.168.1.1
    DNS : 120.196.165.24
        211.136.192.6
    vmware中网络使用桥接方式 , 勾选 复制物理连接到网络 。选择 对应的无线网卡其他都去掉。

Centos6.9-x64
    IP: 192.168.1.6 /255.255.255.0 / 192.168.1.1 同一网段

   CentOS7 - x86 要注意添加网卡,并注意网络设置,GATEWAY网关
     1) 关闭虚拟机. VMare workstation 对应虚拟机安装目录中的.vmx添加ethernet0.virtualDev = "e1000"
    2) 重启,ip addr -> cp /etc/sysconfig/network-scripts/ifg-lo /ect/sysconfig/network-scripts/ifg-ens33

检测 网络设置是否正确

2, 虚拟机添加一个硬盘用来学习 20G SCSI
  reboot
  fdisk /dev/sdb
  mkfs.ext4 /dev/sdb1
  echo "/dev/sdb1 /learn ext4 defaults 0 0 " >> /etc/fstab

3, 添加用户kk4728
  useradd kk4728
  passwd kk4728
 添加sudo用户, /etc/sudoers 添加 kk4728 ALL=(ALL) ALL
 修改学习盘权限
     chown -R kk4728 /learn
    chgrp -R kk4728 /learn
    chmod -R 775 /learn

4, 设置环境变量
   vi ~/.bash_profile添加
   PATH=$PATH:.
  让系统可以查找当前可执行文件

5,同步时间
sudo yum install ntp
 sudo ntpdate time.nist.gov

6 安装依赖项
   sudo yum install -y gcc gcc-c++ gdb ctags ncurses-devel libevent-devel git automake xz zlib-devel cmake libxml2 libxslt libxslt-devel kernel-devel wget openssl openssl-devel

CentOS7 中 默认安装 gcc4.8.5
  glibc-2.17
  python-2.7.5

7, 升级glibc
  wget http://ftp.gnu.org/pub/gnu/glibc/glibc-2.17.tar.xz
  xz -d glibc-2.17.tar.xz
  tar -xvf glibc-2.17.tar
  cd glibc-2.17
  mkdir build
  cd build
  ../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin
  sudo make && make install

安装时出错 libc.a 写权限失败 . 分开安装
   sudo make
  sudo make install

验证:
     x64: strings /lib64/libc.so.6 | grep GLIBC
    x86: strings /lib/libc.so.6 | grep GLIBC

如果这里验证失败。应该是libc.so.6(软连接)指向的路径不对 这里先不升级,按后期需要升级。libc.so.6指向的文件太关键;
   使用不当会引起系统无法登录或重启, 轻则部分指令段错误!!!
   find / -name "libc.so.6"
  cp /usr/glibc-2.17/lib/libc-2.17.so /lib/libc-2.17.so
  rm -rf /lib/libc.so.6
  之后如果引发异常,主要是libc.so.6是系统核心链接库。删除后引发大部分指令出错!
  需要重新创建链接,但是ln 也是需要libc.so.6的。 需要手工添加LD_PRELOAD路径
   [root#localhost ~ ] LD_PRELOAD=/lib/libc-2.17.so ln -s /lib/libc-2.17.so /lib/libc.so.6
  再次验证OK

8,安装Python2.7.13 (CentOS7 -> Python 2.7.5)
  wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
  xz -d Python-2.7.13.tar.xz
  tar -xvf Python-2.7.13.tar
  cd Python-2.7.13
  ./configure --enable-shared
  sudo make
  sudo make install
  /usr/local/bin/python2.7 -V
  提示错误

   权限切换回root
  vi /etc/ld.so.conf 添加/usr/local/lib 保存

   /sbin/ldconfig
  /sbin/ldconfig –v
  mv /usr/bin/python /usr/bin/python.bak
  ln -s /usr/local/bin/python2.7 /usr/bin/python
  vi /usr/bin/yum
  改成 #!/usr/bin/python2.6

将权限切换回kk4728

8 组件安装
   安装setuptools
    wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python
  pip安装
     wget –no-check-certificate https://github.com/pypa/pip/archive/7.1.0.tar.gz
    tar zvxf 7.1.0.tar.gz #解压文件
     cd pip-7.1.0
    sudo python setup.py install

CentOS7 - x86
  wget –no-check-certificate https://github.com/pypa/pip/archive/9.0.0.tar.gz
  tar zvxf 9.0.0.tar.gz #解压文件
   cd pip-9.0.0
  sudo python setup.py install

权限改为root
  pip install requests
  pip install lxml
  pip install cssselect

安装flake8
  pip install flake8

权限改回kk4728

9 升级vim8.0
  wget https://github.com/vim/vim/archive/master.zip

权限改成root
  yum install unzip
  unzip master.zip
  cd vim-master
  cd src/
  ./configure --with-features=huge --enable-python3interp --enable-pythoninterp=yes --enable-rubyinterp --enable-luainterp --enable-multibyte --enable-cscope
  //--prefix=/usr/local/vim
  //--enable-perlinterp
  make
  sudo make install

权限改回kk4728

vim --version
  验证是否安装vim --version | grep python


10 vimrc 插件安装
   git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
  vim .bash_profile 中添加alias vi=vim
  mv ~/.vimrc ~/.vimrc.bak
  Vundle插件管理的路径:~/.vim/bundle/Vundle.vim

.vimrc暂时配置
   """""""""""""""""""""""""""""""""""""""""""""
  filetype off
  set rtp+=~/.vim/bundle/Vundle.vim
  call vundle#begin()
  Plugin 'VundleVim/Vundle.vim'
  " My Plugins here:

Plugin 'bling/vim-airline'
  Plugin 'scrooloose/nerdtree'
  Plugin 'kien/ctrlp.vim'
  Plugin 'taglist.vim'
  Plugin 'Valloric/YouCompleteMe'
  Plugin 'winmanager'
  let g:winManagerWindowLayout="NERDTree|TagList"
  let g:NERDTree_title="[NERDTree]"
  function! NERDTree_Start()
  exec 'NERDTree'
  endfunction
  function! NERDTree_IsValid()
  return 1
  endfunction

" All of your Plugins must be added before the following line
  call vundle#end() " required
  filetype plugin indent on " required


  //安装时间较长 十几分钟
   vim中:PluginInstall
  cmd: vim +PluginInstall +qall

11 更新gcc至6.3.0 安装时间太长 担心权限问题中途中断。这里全部使用root安装
   wget http://ftp.gnu.org/gnu/gcc/gcc-6.3.0/gcc-6.3.0.tar.bz2
  tar -jxvf gcc-6.3.0.tar.bz2
  cd gcc-6.3.0
  ./contrib/download_prerequisites
  cd ..
  mkdir gcc-build-6.3.0
  cd gcc-build-6.3.0
  ../gcc-6.3.0/configure --enable-checking=release --enable-languages=c,c++ --disable-multilib

######################################################
  这里要注意:按需要移除之前gcc版本
   yum remove gcc
  yum remove g++
  yum remove gcc-c++


  /lib/cpp fails sanity check的解决方法

在某些软件的时候,运行./configure 会报错,错误提示为:
  configure: error: C++ preprocessor “/lib/cpp” sanity check
  check See `config.log’ for more details
  ######################################################

make -j7
  make install

处理libstdc++.so.6 以处理器x86 x64不同而不同 find / -name "libstdc++.*"
    x64: cp libstdc++.so.6.0.19 /usr/lib64/libstdc++.so.6.0.19
      ln -sf /usr/lib64/libstdc++.so.6.0.19 /usr/lib64/libstdc++.so.6
    x32: cp /usr/local/lib/libstdc++.so.6.0.22 /usr/lib/libstdc++.so.6.0.22
      ln -sf /usr/lib/libstdc++.so.6.0.22 /usr/lib/libstdc++.so.6
  输入strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX查看成功
   strings /usr/lib/libstdc++.so.6 | grep GLIBCXX
  GLIBCXX_3.4.8
  GLIBCXX_3.4.9
  GLIBCXX_3.4.10
  GLIBCXX_3.4.11
  GLIBCXX_3.4.12
  GLIBCXX_3.4.13
  GLIBCXX_3.4.14
  GLIBCXX_3.4.15
  GLIBCXX_3.4.16
  GLIBCXX_3.4.17
  GLIBCXX_3.4.18
  GLIBCXX_3.4.19
  GLIBCXX_3.4.20
  GLIBCXX_3.4.21
  GLIBCXX_3.4.22
  GLIBCXX_FORCE_NEW
  GLIBCXX_DEBUG_MESSAGE_LENGTH


12 安装clang : 这里不再重新编译,直接下载更新好的

 i686: i386的一个子集,支持的cpu从Pentium 2 (686)开始,之前的型号不支持.
   i386: 适用于intel和AMD所有32位的cpu.以及via采用X86架构的32的cpu.
   intel平台包括8086,80286,80386,80486,奔腾系列(1.2.3.4)、赛扬系列,Pentium D系列以及centrino P-M,core duo 等.
   X86_64: 适用于intel的Core 2 Duo, Centrino Core 2 Duo, and Xeon 和AMD Athlon64/x2, Sempron64/x2, Duron64等采用X86架构的64位cpu.

 wget http://llvm.org/releases/4.0.1/clang+llvm-4.0.1-x86_64-linux-gnu-Fedora-25.tar.xz
  xz -d clang+llvm-4.0.1-x86_64-linux-gnu-Fedora-25.tar.xz
  tar xvf clang+llvm-4.0.1-x86_64-linux-gnu-Fedora-25.tar
  cd clang+llvm-4.0.1-x86_64-linux-gnu-Fedora-25

x64:
    wget http://llvm.org/releases/3.5.1/clang+llvm-3.5.1-x86_64-fedora20.tar.xz
    xz -d clang+llvm-3.5.1-x86_64-fedora20.tar.xz
    tar xvf clang+llvm-3.5.1-x86_64-fedora20.tar
    cd clang+llvm-3.5.1-x86_64-fedora20
  x86:
    wget http://llvm.org/releases/3.5.1/clang+llvm-3.5.1-i686-fedora20.tar.xz
    xz -d clang+llvm-3.5.1-i686-fedora20.tar.xz
    tar xvf clang+llvm-3.5.1-i686-fedora20.tar
    cd clang+llvm-3.5.1-i686-fedora20

以上两种应该都可以,反正都是编译好了的就行了。这里我保守用了3.5.1版本的。文件小点 100多M 4.0.1 700多M

root权限下
   mkdir /usr/clang_351
  cp -r /learn/clang+llvm-3.5.1-x86_64-fedora2/bin /usr/clang_351
  cp -r /learn/clang+llvm-3.5.1-x86_64-fedora2/lib /usr/clang_351 ;libclang.so 在该目录中,后面编译ycm时需要
   cp -r /learn/clang+llvm-3.5.1-x86_64-fedora2/lib /usr/clang_351 ;生成ycm_core需要

   kk4728权限:
   vi ~/.bash_profile 添加
   PATH=/usr/clang_351/bin:$PATH
  export PATH

source ~/.bash_profile更新

13 安装YouCompleteMe

cp /usr/clang_3_5/lib/libclang.so ~/.vim/bundle/YouCompleteMe/python/libclang.so

cd ~
  mkdir build
  cd build
  cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=/usr/clang_351/ . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
  cmake -G "Unix Makefiles" . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp
  提示:编译器不支持 C++11
  Your C++ compiler does NOT fully support C++11.

于是 find /usr -name "gcc" 发现 /usr/bin/gcc版本仍为4.4.7 从而备份/usr/bin/gcc 再试
   由于之前安装gcc-6.3.0时没有移除之前 4.4.7版本
   所以 sudo yum remove gcc
  sudo yum remove g++
  sudo yum remove gcc-c++

cp /usr/local/bin/gcc /usr/bin/gcc
  在build目录下删除 之前安装失败的中间文件 rm -rf *

//这里需要注意的是,~/ycm_temp/llvm_root_dir中包含的是根据第一步下载的压缩包解压出来的内容(包括include, bin等等文件)。
   //中途出现错误 clang-c/Index.h找不到 就是PATH_TO_LLVM_ROOT路径设置错误!

   rm -rf CMakeCache.txt //防止中途编译异常带来的问题
   make ycm_core
  编译出现问题:可能与编译器版本有关 gcc6.3.0 可能太新了 -> 后查极有可能时clang3.5.1偏旧 改成 4.0.1可能能解决
  --> 再 make ycm_core
  cp /usr/clang_351/lib/libclang.so ~/.vim/bundle/YouCompleteMe/python/libclang.so 貌似不会出错

   [ 72%] Building CXX object ycm/CMakeFiles/ycm_core.dir/ClangCompleter/TranslationUnit.cpp.o
  /home/kk4728/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/ClangCompleter/TranslationUnit.cpp 在函数‘unsigned int YouCompleteMe::{匿名}::EditingOptions()’中:
  /home/kk4728/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/ClangCompleter/TranslationUnit.cpp:43:10: 错误:‘CXTranslationUnit_CreatePreambleOnFirstParse’在此作用域中尚未声明
   CXTranslationUnit_CreatePreambleOnFirstParse |
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  /home/kk4728/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/ClangCompleter/TranslationUnit.cpp:44:10: 错误:‘CXTranslationUnit_KeepGoing’在此作用域中尚未声明
   CXTranslationUnit_KeepGoing |
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
  /home/kk4728/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/ClangCompleter/TranslationUnit.cpp 在构造函数‘YouCompleteMe::TranslationUnit::TranslationUnit(const string&,     const std::vector<UnsavedFile>&, const std::vector<std::__cxx11::basic_string<char> >&, CXIndex)’中:
  /home/kk4728/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/ClangCompleter/TranslationUnit.cpp:105:51: 错误:‘clang_parseTranslationUnit2FullArgv’在此作用域中尚未声明
   &clang_translation_unit_ );
 ^
 make[3]: *** [ycm/CMakeFiles/ycm_core.dir/ClangCompleter/TranslationUnit.cpp.o] 错误 1
 make[2]: *** [ycm/CMakeFiles/ycm_core.dir/all] 错误 2
 make[1]: *** [ycm/CMakeFiles/ycm_core.dir/rule] 错误 2

 


  make ycm_support_libs x64中失败!

//暂时越过 make ycm_make 和make ycm_support_libs
  直接进入到YCM安装目录
   ./install.sh --clang-completer
  在x64中运行正常,在x86中出现clang.5.0版本库异常,无法自动下载。

14 vimrc
  let g:ycm_global_ycm_extra_conf=‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py‘
  检查配置
     echo | clang -std=c++11 -stdlib=libc++ -v -E -x c++ -

上述.ycm_extra_conf.py中添加c库支持
   '-isystem',
  '/usr/include',
  '-isystem',
  '/usr/local/include',
  '-isystem',
  '/usr/clang_3_5/bin/../include/c++/v1',
  '-isystem',
  '/usr/clang_3_5/bin/../lib/clang/3.5.1/include',

安装 man
  yum install man
  yum install man-pages.noarch man-pages-overrides.noarch

将en下的man复制过来,先凑合用用:
   cp /usr/share/locale/en/LC_MESSAGES/man /usr/share/locale/zh/LC_MESSAGES/

整个vimrc配置如下
   """""""""""""""""""""""""""""""""""""""""""
  filetype off
  set rtp+=~/.vim/bundle/Vundle.vim
  call vundle#begin()
  Plugin 'gmarik/Vundle.vim'
  " My Plugins here:"

Plugin 'bling/vim-airline'
  "let g:airline_powerline_fonts = 1"
  set laststatus=2
  set t_Co=256

Plugin 'scrooloose/nerdtree'
  let mapleader=","
  nmap <silent> <leader>ne :NERDTree<CR>
  nmap <silent> <leader>nc :NERDTreeClose<CR>
  "map <silent> <F3> :NERDTreeToggle<CR>"
  Plugin 'kien/ctrlp.vim'
  "Plugin 'altercation/vim-colors-solarized'"
  let g:ctrlp_custom_ignore = {
  \ 'dir': 'vendor/bundle/*\|vendor/cache/*\|public\|spec',
  \ 'file': '\v\.(exe|so|dll|swp|log|jpg|png|json)$',
  \ }
  syntax enable
  set background=dark
  let g:solarized_termcolors=256
  " colorscheme flatcolor

Plugin 'taglist.vim'
  let Tlist_Show_One_File = 1 "不同时显示多个文件的tag,只显示当前文件的"
  let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一个窗口,则退出vim"
  "let Tlist_Use_Right_Window = 1" "在右侧窗口中显示taglist窗口"
  "nmap <F4> :TlistToggle<cr>"

Plugin 'Valloric/YouCompleteMe'
  Plugin 'rdnetto/YCM-Generator'
  let g:ycm_global_ycm_extra_conf = '~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ycm/.ycm_extra_conf.py'
  let g:ycm_confirm_extra_conf = 0
  nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
  nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
  nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
  inoremap <c-o> <c-x><c-o>
  let g:ycm_semantic_triggers = {
  \ 'c' : ['->', ' ', '.', ' ', '(', '[', '&'],
  \ 'cpp,objcpp' : ['->', '.', ' ', '(', '[', '&', '::'],
  \ 'perl' : ['->', '::', ' '],
  \ 'php' : ['->', '::', '.'],
  \ 'cs,java,javascript,d,vim,python,perl6,scala,vb,elixir,go' : ['.'],
  \ 'ruby' : ['.', '::'],
  \ 'lua' : ['.', ':']
  \ }

Plugin 'winmanager'
  let g:winManagerWindowLayout="NERDTree|TagList"
  let g:NERDTree_title="[NERDTree]"
  function! NERDTree_Start()
  exec 'NERDTree'
  endfunction
  function! NERDTree_IsValid()
  return 1
  endfunction
  nmap <silent> <F2> :if IsWinManagerVisible() <BAR> WMToggle<CR> <BAR> else <BAR> WMToggle<CR>:q<CR> endif <CR><CR>

" All of your Plugins must be added before the following line"
  call vundle#end() " required"
  filetype plugin indent on " required"

set nu "show line number"
  set ts=4 "tab length is 4"
  autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
  set list listchars=tab:→\ ,trail:·
  set hlsearch incsearch smartcase ignorecase
  autocmd BufNewFile,BufRead *.json set filetype=javascript


   nmap mm :call ChangeMouse()<cr>
  function ChangeMouse()
  if &mouse == "a"
  set mouse-=a
  else
  let &mouse = "a"
  endif
  endfunction

set nocompatible
  set autoindent
  set backspace=indent,eol,start

set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
  set termencoding=utf-8
  set encoding=utf-8
  set fileencodings=ucs-bom,utf-8,cp936
  set fileencoding=utf-8
  
   安装 TMUX
  yum install automake
  yum install libevent-devel ncurses-devel

安装TMUX错误:‘EVBUFFER_EOL_LF’未声明 ----未尝试!!!!!!!!!!

原因是使用的libevent的版本太低造成的,要求libevent>= 2.0.10-stable


15 清理
   clang 编译好了之后,不用安装,仅仅为了得到libclang.so 已经复制到 /usr/clang_351中
   python2.7 也是临时的,作为clang的依赖 不需要安装什么第三方库
   gcc 也可以是临时的, 用来编译clang, 还可以得到libstdc++.so

清理后空间不怎么减少!!!!!!!!!!!!!!!!!!!

相关推荐