Skip to content

Instantly share code, notes, and snippets.

@darcyparker
Created May 14, 2013 21:49
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save darcyparker/5579887 to your computer and use it in GitHub Desktop.
Compiling 64 bit Vim using free MS Visual Studio 2012 Express

#Compiling 64 bit Vim using free MS Visual Studio 2012 Express

I needed vim with Python support on Win7. The following are my notes.

##Background on why At first this sounds simple... but challenges included:

  • Vim has numerous download options, but none were quite right.
    • gvim73_46.exe is old and doesn't have all the features I want
    • Cream maintains recent builds compiled with mingw-w64 and they have Python support. But in practice it doesn't work...
      • All popular distributions of Python are compiled against MSVC and not mingw-w64. So the python support fails because the DLLs aren't binary compatible with MSVC. (Try :echo has('python') in vim and you will see it returns false.)
      • There are tools to work with binaries from MSCV with mingw-w64, but I don't have the experience. And I speculate there would be yet another problem with some python module that used native code.
      • There are instructions on how to compile a 64 bit target of Python with mingw-w64. I think I could figure it out... but it was more than I wanted to do. And I am still uncertain if a vim plugin that I use requires a python module that is implemented with native code that was compiled with MSVC. I didn't want to have to hunt down and rebuild every python module with mingw-w64. There also has to be a reason that Python isn't really developed using mingw-w64. Maybe in the future we'll see better support of mingw-w64 in the python community.
    • Yongwei's Build is great. I used it successfully for awhile, but eventually I needed a 64 bit python on my OS and installing both 32 bit and 64 bit versions proved to be difficult (for me atleast... I have no experience with python other than enough to use tools written in python.) And the 32 bit vim and 64 bit python binaries are not compatible. Try :echo has('python') and you will see it fails when 64 bit python is installed.
  • I generally aim to use Chocolatey to install apps on my machine.
    • I use nodejs and yeoman... nodejs is a 64 bit application. (You can get a 32 bit version, but not with chocolatey...)
      • yeoman is a tool for nodejs and it has generators (ex angularjs) that rely on node-gyp, which in turn relies on python. Since Nodejs is 64 bit, I need a 64 bit Python.
  • I tried compiling with mingw-w64... and I succeeded with the exception of getting Python support

Based on the above challenges, it became clear that I needed a vim compiled with a 64 bit target that was binary compatible with MSVC so I could use vim. Trying to use mingw-w64 was an interesting exercises, but not sufficient.

##Solution - compiling vim from source with MS Visual Studio 2012 Express

Note: MS Visual Studio 2012 Express is the only free MSVC compiler with a 64 bit target. Previous versions of MS Visual Studio Express are free. But the earlier express versions don't let you target 64 bit.

  1. Install vim

    • I used Chocolatey: cinst KickAssVim which depends on the nuget vim.
    • I could have installed this with make I suppose... but this was easier for me.
  2. Install MS Visual Studio 2012 Express with Chocolatey cinst VisualStudio2012WDX

  3. Install Windows 7.0 SDK v7.1

    • At this time (5/14/2013), I had to do this manually because there is no chocolatey nuget for it.
  4. Clone the vim source code

    • Install Mercurial if you haven't already: cinst hg
    • Make an appropriate folder to clone source code in.
    • hg clone https://vim.googlecode.com/hg/ vim
    • See Vim from Mercurial for more info.
  5. Created a simple batch file to configure my settings

    • cd to the vim/src folder

    Note: This is a simple batch file that was created based on notes in Make_mvc.mak and the other *.bat files in vim/src folder.

    @echo off
    setlocal
    
    set SDK_INCLUDE_DIR=C:\Program Files\Microsoft SDKs\Windows\v7.1\Include
    SET VCDIR=C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\
    call "%VCDIR%\vcvarsall.bat" x86_amd64
    
    set CPU=AMD64
    set GUI=yes
    set OLE=yes
    
    set PYTHON=C:\bin\python27
    set DYNAMIC_PYTHON=yes
    set PYTHON_VER=27
    
    set PYTHON3=C:\bin\python33
    set DYNAMIC_PYTHON3=yes
    set PYTHON3_VER=33
    
    set IME=yes
    set GIME=yes
    set CSCOPE=yes
    set MBYTE=yes
    set FEATURES=HUGE
    set OPTIMIZE=MAXSPEED
    set USERNAME=DarcyParker
    
    echo About to make clean
    pause
    call "%VCDIR%bin\nmake" -f Make_mvc.mak clean
    
    echo About to make gvim
    pause
    call "%VCDIR%bin\nmake" -f Make_mvc.mak
    
    echo About to make vim.exe
    pause
    set GUI=
    set OLE=
    set IME=
    set GIME=
    call "%VCDIR%bin\nmake" -f Make_mvc.mak
    
    endlocal
  6. Run the bat file created above.

  7. I then manually copy the built items to my original vim73 installation

    • ie copy and overwrite files to C:\Program Files (x86)\vim\vim73

    Of course this is a win32 folder... but I am okay with this.

    • Built files to copy:
      • src\gvim.exe
      • src\vim.exe
      • src\vimrun.exe
      • src\xxd\xxd.exe
      • src\GvimExt\gvimext.dll
@neilflodin
Copy link

This finally worked for me on Windows 10, I used Visual Studio 14.0 though instead (it worked fine). Thank you so much - you're a lifesaver!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment