Skip to content

Setting up irony mode on Windows using MSVC

3246251196 edited this page Jun 27, 2018 · 20 revisions

Establishing an environment

In order to use Irony-Mode for completions it is suggested to load emacs after establishing the MSVS environment. I personally do this via the following batch file/script:

echo "Establishing Visual Studio variables..."
call "c:\Program Files (x86)\Microsoft Visual Studio 14.0\VC/vcvarsall.bat" amd64

echo "Running emacs..."
c:\emacs-24.5\bin\runemacs.exe

The location of 'vcvarsall.bat' changes all the time. The example above happens to be where the batch file is located for Visual Studio 2015. You should seek the location and update the batch file as necessary. Further, this example establishes the 64-bit environment.

Downloading llvm/clang

Personally, I use the latest version of 'llvm/clang' from trunk since I have been interested in debugging some its 'Sema' code. Anyway, it is enough to download the latest release (currently the website is: http://releases.llvm.org/download.html and you can download the Pre-Built binaries: Clang for Windows (64-bit)).

Of course, you do not have to use the 64 bit version.

Adding the libclang library to your path

When generating the build environment via 'cmake', having the location of path to 'libclang.dll' in your '%PATH%' variable is all that is required for 'cmake' to detect the 'clang' library. You can add this location to your '%PATH%' using the standard Windows environment.

Compiling the irony server

If you have downloaded the 64-bit version of clang you will need to add additional arguments to 'cmake' to tell it to compile the 'irony' server in 64-bits. You can do this by:

M-x customize-group irony

and adding:

-G Visual Studio 14 2015 Win64

as two separate arguments to 'Irony Extra Cmake Args'

After that,

M-x irony-install-server

Should complete.

.clang_complete

So far I have never used any other mechanism than using the '.clang_complete' file. This happens to be convenient for me at work since I use the same directory for our product at work: 'd:/work/trunk'; the version control repository is always checked out there and I merely add a the '.clang_complete' file to the source code top level directory. This approach is okay for me - other people may find it cumbersome. I cannot offer advice on the "json" technique since I have never used it. It is enough for me to say, here, that adding the -I flags to the '.clang_complete' file has served me well so far. You should not need to add the c++/MSVS std include directory since 'clang' should detect this from your environment established via 'vsvarsall.bat'.