Skip to content

Windows Installation Guide for Unix‐like Environments

zeertzjq edited this page Jun 15, 2022 · 5 revisions

Windows is officially supported by YouCompleteMe (using MSVC). Please follow the instructions in the README.md. This page is for installing YCM on Unix-like environments (Cygwin, MinGW, MSYS2) and is community maintained. Do NOT create an issue if these instructions are not working for you.

Instructions for 64-bit using MSYS2

  1. Download the latest version of MSYS2 and add it to your PATH
  2. Install Python 3.8 x86-64 for Windows.
  3. Install Vim 64-bit from these builds
  4. Install YouCompleteMe using Vundle
  5. Run the below commands in the msys2 terminal:
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-python git msys2-runtime-devel 
export PATH=/mingw64/bin/:$PATH
cp /usr/lib/librt.a /mingw64/lib

cd /c/users/<USERNAME> # <USERNAME> is your windows username
mkdir ycm-build
cmake -G "Unix Makefiles" . /c/<PATH TO YouCompleteMe>/third_party/ycmd/cpp
cmake --build . --target ycm_core --config Release

python -m pip install watchdog
  1. If you are using Vim on native Windows, add this to the top of you vimrc:
let &pythonthreedll="<PATH TO YOUR PYTHON INSTALLATION>\\python38.dll"                   "E.g.:C:\\Python\\python38.dll
let g:ycm_server_python_interpreter="<PATH TO MSYS2 INSTALLATION>\\mingw64\\bin\\python" "E.g.: C:\\MSYS2\\mingw64\\bin\\python

Instructions for 64-bit using MinGW64 (Warning: Deprecated)

Here's a sequence of steps that worked on Windows 8 x64. These instructions build YCM without semantic support for C-family languages. IMPORTANT: If you use version 4.8.1 or greater it is very likely that error undefined reference to `InterlockedCompareExchange' will occur. In that case use earlier version of compiler or after step 6. replace file cpp\BoostParts\boost\detail\interlocked.hpp with that file.

  1. Download the -win64 version of MinGW64. Extract the archive to C:\MinGW64 and add C:\MinGW64\bin to your PATH
  2. Install Python 2.7 x86-64 for Windows.
  3. IMPORTANT: You need to have a 64-bit build of Vim for YCM to work. Haroogan has 64-bit builds that are confirmed working.
  4. Install CMake.
  5. Install Vundle.
  6. Install YouCompleteMe using Vundle.
  7. Edit %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd\cpp\CMakeLists.txt and add the following lines:
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -include cmath")
add_definitions(-DBOOST_PYTHON_SOURCE)
add_definitions(-DBOOST_THREAD_BUILD_DLL)
add_definitions(-DMS_WIN64)
  1. Edit %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd\cpp\ycm\ycm_core.cpp and comment out the last three lines so they look like this:
// namespace boost {
// void tss_cleanup_implemented() {}
// };
  1. Create a build directory and cd into it.
  2. Run cmake -G "MinGW Makefiles" . %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd\cpp. If you have ever renamed the MinGW's make program (originally mingw32-make.exe), then you should probably add the following argument to let cmake know where to find it: -D"CMAKE_MAKE_PROGRAM:PATH=C:/MinGW64/bin/NAME-OF-YOUR-MAKE.exe"
  3. Run mingw32-make ycm_core (Don't worry about the 32 in that command)
  4. Copy ycm_core.pyd from ycm\ to %USERPROFILE%\vimfiles\bundle\YouCompleteMe\python

Instructions for 64-bit using MinGW64 (clang) (Warning: Deprecated)

Here's a sequence of steps that worked on Windows 7 x64. These instructions build YCM with semantic support for C-family languages.

  1. Download the -win64 mingw-builds version of MinGW-w64. Extract the archive to C:\MinGW64 and add C:\MinGW64\bin to your PATH
  2. Install Python 2.7 x86-64 for Windows to C:\Python27.
  3. You can try to make libpython27.a or download from here (tip: you can unpack installer with 7-Zip). Make sure that you put libpython27.a in C:\Python27\libs directory.
  4. Compile LLVM with clang or download again from Haroogan. Click on proper number in download section to download LLVM. Unpack it to C:\LLVM
  5. You need to have a 64-bit build of Vim for YCM to work. Haroogan has 64-bit builds that are confirmed working.
  6. Install CMake.
  7. Install:
    • Vundle and install YouCompleteMe using Vundle
    • OR Pathogen, make dir in vimfiles\bundle\YouCompleteMe, cd in Git Bash into it and run:
git clone https://github.com/Valloric/YouCompleteMe .
git submodule update --init --recursive
  1. Replace file %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd\cpp\BoostParts\boost\detail\interlocked.hpp with that file.
  2. Edit %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd\cpp\CMakeLists.txt and add the following lines:
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -include cmath")
add_definitions(-DBOOST_PYTHON_SOURCE)
add_definitions(-DBOOST_THREAD_BUILD_DLL)
add_definitions(-DMS_WIN64)
  1. Create a build directory and cd into it.
  2. Run cmake -G "MinGW Makefiles" -DPATH_TO_LLVM_ROOT=C:\LLVM . %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd\cpp. If you have ever renamed the MinGW's make program (originally mingw32-make.exe), then you should probably add the following argument to let cmake know where to find it: -D"CMAKE_MAKE_PROGRAM:PATH=C:/MinGW64/bin/NAME-OF-YOUR-MAKE.exe"
  3. Run mingw32-make ycm_support_libs (Don't worry about the 32 in that command)
  4. (Obsolete) Copy ycm_core.pyd, ycm_client_support.pyd, and libclang.dll from %USERPROFILE%\vimfiles\bundle\YouCompleteMe\third_party\ycmd to %USERPROFILE%\vimfiles\bundle\YouCompleteMe\python

Possible errors:

  • "cmake exit with error and linking to wrong compilers/libraries"
    • Check if you have YouCompleteMe and build directory on the same drive (in this guide C:\) as MinGW, Python and LLVM.
  • if Vim :version indicates +python/dyn then Vim was compiled with Python2 support - that's good. but if Vim :echo has('python') returns 0 then you have the wrong memory model of Python2 installed - bad.
  • Could NOT find PythonLibs (missing: PYTHON_LIBRARIES PYTHON_INCLUDE_DIRS) - caused by %PATH% problems - and not necessarily with Python!
  • step 12. make (90%) - Linking CXX shared library C:\Users\P\vimfiles\bundle\YouCompleteMe\third_party
    ycmd\ycm_core.pyd - C:/MinGW64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.2/../../../../x86_64-w64-mingw3 2/bin/ld.exe: i386 architecture of input file `C:\Python27\libs\libpython27.a(du ks00143.o)' is incompatible with i386:x86-64 output... This is caused by forgetting to reinstall libpython27.a in step 3. after reinstalling Python 2.7 in step 2.
  • "during linking stage occurs undefined reference to `Interlocked...' error"
    • If you are sure that you made step 8. correctly, then probably is error in boost libraries. Wait for update of YouCompleteMe's Boost library or use Google to resolve that issue and then update wiki, please.
  • "during compiling stage occurs undefined reference to `__imp__Py_...'"
    • delete all files from build directory, check if libpython27.a is in C:\Python27\libs directory and repeat from step 11. Check if cmake found libpython27.a.
  • during linking stage "..\BoostParts\libBoostParts.a(tss_dll.cpp.obj):tss_dll.cpp:(.text+0x70): multiple definition of `boost::tss_cleanup_implemented()'"
    • comment out namespace boost { void tss_cleanup_implemented() {} }; in ycm_client_supprt.cpp and ycm_core.cpp
  • if you compiled LLVM on windows with mingw following the instructions at http://stackoverflow.com/questions/9427356/how-to-compile-clang-on-windows note that PATH_TO_LLVM_ROOT will actually need to point to the location of the clang folder under tools, not the top level LLVM folder

Instructions for Cygwin64 (w/o clang) (Warning: Deprecated)

References:

[1] http://stackoverflow.com/a/21820642

[2] https://sourceforge.net/projects/cygwin-ports/

[3] https://github.com/Valloric/YouCompleteMe/issues/684

Prerequisites

  1. gcc --version == 4.9.X
  • You can find this in the cygwin setup installer. Just downgrade gcc.
  • If your cygwin only has gcc >= 5.0, this guide might work, but if it fails, try and compile clang > 3.7, using an equivalent version of cygwin-clang.patch, listed in the next step.
  1. Download or copy the cygwin64 boost.python patch from this gist. Place this in ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ and name it cygwin64.BoostParts.patch

Instructions

  1. Compile YCM as follows:
$ cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/
$ rm *.dll *.dll.a 
$ mkdir -pv cpp/build && cd cpp/
$ patch -p2 < cygwin64.BoostParts.patch #fix boost for cygwin64. Might not be necessary in future YCM released
$ cd build/
$ cmake -DCMAKE_BUILD_TYPE=Release  ..
$ make # replace with make -j <num-of-cores> for speed.
  1. To test that the ycm_core.dll does not cause any segfaults in python attempt the following:
$ cd ../../
$ python.exe # Load python prompt
Python 2.7.10 (default, Jun  1 2015, 18:05:38)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>> import ycm_core
  1. If there are no errors, exit python by typing quit() and hitting enter or hit Ctrl-D.
  2. YCM should work fine in cygwin now! Make sure you've set up your global and per-project .ycm_extra_conf files!

Enjoy!

Instructions for Cygwin64 (w/ clang) (Warning: Deprecated)

Disclaimer: This is what worked for me

Recent versions of cygclang.dll (>3.5) have made some runtime changes that result in python suffering a STATUS_ACCESS_VIOLATION when loading ycm_core.dll (in both 32-bit cygwin and 64-bit cygwin) when using the cygwin-provided development packages (as mentioned below).

Since there are no prepackaged builds of clang or llvm for cygwin that do not have this issue, and simply compiling clang leads to #include file search failures, I've written a guide on patching clang using the cygport project's llvm patches.

References:

[1] http://stackoverflow.com/a/21820642

[2] https://sourceforge.net/projects/cygwin-ports/

[3] https://github.com/Valloric/YouCompleteMe/issues/684

Prerequisites

  1. gcc --version == 4.9.X
  • You can find this in the cygwin setup installer. Just downgrade gcc.
  • If your cygwin only has gcc >= 5.0, this guide might work, but if it fails, try and compile clang > 3.7, using an equivalent version of cygwin-clang.patch, listed in the next step.
  1. Download or copy the cygwin64 boost.python patch from this gist. Place this in ~/.vim/bundle/YouCompleteMe/third_party/ycmd/cpp/ and name it cygwin64.BoostParts.patch
  2. Download 3.5.1-cygwin-clang.patch
  • If your cygwin installation only provides gcc >= 5, get the patch for clang > 3.7 here
  1. Grab the llvm-x.y.z and clang-x.y.z sources from the llvm website

Instructions

  1. Untar these sources as follows:
$ LLVM_VERSION="x.y.z" # replace x.y.z with your version, such as 3.5.1
$ mkdir -pv ~/downloads/src/ && cd ~/downloads/src
$ mv <path-to-llvm-tarfile> . && mv <path-to-clang-tarfile> .
$ tar xvf llvm-${LLVM_VERSION}.src.tar.xz
$ cd llvm-${LLVM_VERSION}.src/tools/ && mkdir -pv clang &&  tar xvf ../../cfe-${LLVM_VERSION}.src.tar.xv -C clang --strip-components=1
$ cd ..
$ patch -p2 < ../${LLVM_VERSION}-cygwin-clang.patch #Patch clang for cygwin
$ unset LLVM_VERSION
  1. Compile
$ ./configure --enable-optimizations --disable-assertions --enable-shared # If the configure command complains about libffi, install libffi-devel ether through setup-x86_64.exe or apt-cyg and re-run it.
$  make && make install # you can also use make -j <number> && make -j <number> install, where <number> is the number of CPU cores you wish to use to compile.
  1. Check that /usr/local/bin/cygclang.dll exists.
  2. Compile YCM as follows:
$ cd ~/.vim/bundle/YouCompleteMe/third_party/ycmd/
$ rm *.dll *.dll.a 
$ mkdir -pv cpp/build && cd cpp/
$ patch -p2 < cygwin64.BoostParts.patch #fix boost for cygwin64. Might not be necessary in future YCM released
$ cd build/
$ cmake -DCMAKE_BUILD_TYPE=Release -DUSE_SYSTEM_BOOST=OFF -DEXTERNAL_LIBCLANG_PATH=/usr/local/bin/cygclang.dll ..
$ make # replace with make -j <num-of-cores> for speed.
  1. To test that the ycm_core.dll does not cause any segfaults in python attempt the following:
$ cd ../../ 
$ python.exe # Load python prompt
Python 2.7.10 (default, Jun  1 2015, 18:05:38)
[GCC 4.9.2] on cygwin
Type "help", "copyright", "credits" or "license" for more information.
>> import ycm_core
  1. If there are no errors, exit python by typing quit() and hitting enter or hit Ctrl-D.
  2. YCM should work fine in cygwin now! Make sure you've set up your global and per-project .ycm_extra_conf files!

Enjoy!