2016年9月13日 星期二

YouCompleteMe in MSYS2 on Windows

Table of Content

To use YouCompleteMe in an MSYS shell, you will need to:
  1. Install MSYS2
  2. Install CMake
  3. build libclang
  4. Install YCM (and vundle, of course)
  5. Bulid YCM

Install MSYS2

reference https://www.youtube.com/watch?v=pb6Yb819pF0
  1. Download MSYS2 64bit version is better
  2. Execute the installer binary, install MSYS2 to  C:\msys64 
  3. Run a MSYS2 shell, execute  update-core 
  4. Close the MSYS2 shell window
  5. Run a MINGW64 shell
  6. Execute  pacman -Su 
  7. Close the MINGW64 shell window
  8. Run a MINGW64 shell
  9. Execute  pacman -Su  AGAIN
  10. Execute  pacman --needed -S git mingw-w64-x86_64-gcc base-devel  install compiler tool chain
Check following:
  1. vim  :echo has('python')  it should be 1
  2.  gcc -v 
  3.  make -v 
  4.  cmake  should NOT installed, if installed, REMOVE it. Because we don't want MINGW's cmake, but Windows'. Only Windows version can generate "MSYS Makefiles" format, which is what we need.

Install CMake

  1. Download from here, download the Windows 64 bit version
  2. Install to  C:\CMake 

Build libclang

reference
http://clang.llvm.org/get_started.html
https://github.com/rust-lang/rust/issues/34489

  1. Get LLVM and Clang source. We don't clone the whole repo, just download the tar file. It's much faster.
    1.  wget http://llvm.org/releases/3.9.0/llvm-3.9.0.src.tar.xz -O llvm.tar.xz 
    2.  wget http://llvm.org/releases/3.9.0/cfe-3.9.0.src.tar.xz -O clang.tar.xz 
    3.  tar xvfJ llvm.tar.xz 
    4.  tar xvfj clang.tar.xz 
    5.  mv clang llvm/tools 
  2. Use CMake to generate make file.
    1. Before run cmake, you need to apply some modification:
      1. Use Windows version python, not MSYS's python, to generate correct source path.  vi llvm/CMakeLists.txt  replace  COMMAND ${PYTHON_EXECUTABLE} ${LLVMBUILDTOOL}  with  COMMAND C:/Python27/python.exe ${LLVMBUILDTOOL} 
      2. Add CXX flag  --Wa,-mbig-obj  otherwise the output .obj file will be too large.
      3. Add LINK flag  -L/usr/lib 
    2. Generate the make file.
      1.  mkdir build-llvm 
      2.  cd build-llvm 
      3.  /c/CMake/bin/cmake.exe -G "MSYS Makefiles" ../llvm 
    3. Make it
      1.  make 
    4. FAIL. Build fail at last step link the result file liblibclang.dll, the error message is ld.exe: cannot find -ldl but I did not pass -ldl to the linker, and I don't know how to remove it. according to http://discourse.chaiscript.com/t/basic-question-about-compiling-chaiscript-with-mingw-g/170 "dl is only needed in unix". so why my toolchain try to link it? after more search, maybe add a -L/usr/lib can fix that problem. That is weird the toolchain didn't add it at default.

To Be Continue




沒有留言:

張貼留言