Tuesday, June 3, 2014

Using clang with YouCompleteMe for IntelliSense auto-complete in Vim


Installing vim (must be 7.3.584 w/ python2 support):

If you have root:

https://github.com/Valloric/YouCompleteMe/wiki/Building-Vim-from-source

If you don't have root:

http://www.vim.org/sources.php
Copy the version you want, extract and cd into it
./configure --with-features=huge --enable-multibyte --enable-rubyinterp --enable-pythoninterp --with-python-config-dir=/tools/devkits/lnx64/python-2.7.5/lib/python2.7/config/ --enable-perlinterp --enable-luainterp --enable-gui=gtk2 --enable-cscope --prefix=<install_dir>
# I used ~/vim74_install/
# Also I had some problems with ruby, so I removed --enable-rubyinterp

make
make install

# remember to setup paths to bin e.g. setenv PATH ~/vim74_install/bin:$PATH

gvim --version

Installing clang (only if your OS isn't supported here http://llvm.org/releases/download.html#3.3)

http://clang.llvm.org/get_started.html

Download llvm, clang, compiler rt, and clang tools extra, from:
http://llvm.org/releases/download.html#3.3
tar xzf llvm-3.4.1.src.tar.gz 
mv llvm-3.4.1.src llvm-3.4.1

cd llvm-3.4.1/tools/
tar xzf ../../cfe-3.4.1.src.tar.gz 
mv cfe-3.4.1.src clang
cd ../..

cd llvm-3.4.1/tools/clang/tools
tar xzf ../../../../clang-tools-extra-3.4.src.tar.gz 
mv clang-tools-extra-3.4/ extra/
cd ../../../..

cd llvm-3.4.1/projects/
tar xzf ../../compiler-rt-3.4.src.tar.gz 
mv compiler-rt-3.4/ compiler-rt/
cd ../..

mkdir llvm-3.4.1_build/
cd llvm-3.4.1_build/
../llvm-3.4.1/configure --prefix=~/llvm-3.4.1_install
make

#mkdir llvm-3.4.1_linstall/
# remember to setup paths to bin e.g. setenv PATH ~/llvm-3.4.1_linstall/bin:$PATH

Installing CMake

wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
tar xzf cmake-2.8.12.2.tar.gz
cd cmake-2.8.12.2
./configure --prefix=<install_dir>
# I used ~/cmake-2.8.12.2_install/

# ERROR: version `GLIBCXX_3.4.15' not found
# Luckily I had gcc-4.8.2 installed which has libstdc++.so.6 with the correct GLIBCXX.  To point to that I used:
setenv LD_LIBRARY_PATH /tools/devkits/lnx64/gcc-4.8.2/lib64:$LD_LIBRARY_PATH
# rerun config

gmake

# remember to setup paths to bin e.g. setenv PATH ~/cmake-2.8.12.2_install//bin:$PATH

cmake -version

Installing YouCompleteMe

Reference: https://github.com/Valloric/YouCompleteMe && http://valloric.github.io/YouCompleteMe/

cd ~/.vim/bundle/
git clone https://github.com/Valloric/YouCompleteMe
cd YouCompleteMe
git submodule update --init --recursive
#./install.sh --clang-completer << didn't work for me

Download the binary unless you built clang:
http://llvm.org/releases/download.html#3.3
Extract the archive and this path that you extract llvm to is used below as ~/ycm_temp/llvm_root_dircd

cmake -G "Unix Makefiles" -DPATH_TO_LLVM_ROOT=~/ycm_temp/llvm_root_dir . ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp

make ycm_support_libs


# -- If you get this:
#    Your C++ compiler does NOT support C++11, will compile in C++03 mode.
# You should get:
#    Your C++ compiler supports C++11, compiling in that mode.
# Then the c++/cpp/g++/cpp compile being used by cmake is incorrect.  This is represented by 
# CMAKE_CXX_COMPILER && CMAKE_C_COMPILER
# -- Then do this:
# You can override this with
setenv CC /tools/devkits/lnx64/gcc-4.8.2/bin/gcc
setenv CXX /tools/devkits/lnx64/gcc-4.8.2/bin/g++

# -- If you get this:
# Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS)
#   (Required is at least version "2.6")
# Call Stack (most recent call first):
#   ~/cmake-2.8.12.2_install/Modules/FindPackageHandleStandardArgs.cmake:315
# (_FPHSA_FAILURE_MESSAGE)
#   ~/cmake-2.8.12.2_install/Modules/FindPythonLibs.cmake:186
# (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
#   BoostParts/CMakeLists.txt:30 (find_package)
# -- Then do this:
# open third_party/ycmd/cpp/BoostParts/CMakeLists.txt
# open third_party/ycmd/cpp/ycm/CMakeLists.txt
# after cmake_minimum_required and before project:
set( PYTHON_LIBRARY /tools/devkits/lnx64/python-2.7.5/lib/ )
set( PYTHON_INCLUDE_DIR /tools/devkits/lnx64/python-2.7.5/include/python2.7/ )
# rerun ./install.sh --clang-completer





No comments:

Post a Comment