Skip to content

Setting up irony mode on Windows using MSVC

3246251196 edited this page Feb 13, 2016 · 20 revisions

The findings in this article are based on https://github.com/Sarcasm/irony-mode/issues/280; All findings have been based on the following system: MSVS 2015, clang 3.7 (x86), Windows 7 x64, Emacs 24.5 and Irony server version (TODO)

Establishing an environment

In order to use Irony-Mode for completions for an MSVS 2015 project it is suggested to load emacs after establishing the MSVS environment. This can be done in a number of ways, but I convenient way is to create batch file along the lines of:

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`

After running this batch file, the environment variables needed by Clang are set up; these are variables such as the Windows SDK includes and MSVS includes, etc.

.clang_complete

Now we need to supply the compiler options to Clang for completions. At the very least, you should have the following in your .clang_complete file:

-target
i686-pc-windows-msvc
-fms-extensions
-fms-compatibility
-fms-compatibility-version=19
-fdelayed-template-parsing
```

This basic set of options tells Clang that it should be dealing with the MSVS context.

However, that is not all. The chances are you are working with a project that has include directories, definitions etc. Therefore, in addition to the flags above, you should add:

```
--driver-mode=cl
/nologo
/DWIN32
/D_WINDOWS
/W3
/GR
/EHsc
/EHs
/D_HAS_EXCEPTIONS=0
```

All of the options that start with / are MSVS style options. The ones provided here are just an example, you should ideally replace all of them with whatever your project uses in MSVS.

Clone this wiki locally