-
Notifications
You must be signed in to change notification settings - Fork 99
Setting up irony mode on Windows using MSVC
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)
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.
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. Important to note is the use of --driver-mode=cl
: this is mandatory if what follows are MSVC style options!
Yes, this is annoying...
It is sometimes hard to track down. In my personal experience (3246251196) this is indicative of mal-configuration. That is, somewhere you have forgot to add an include or flag (even the most innocent of flags can cause an issue).
There is a hack available (I would prefer to see this as an option - ask Sarcasm about this). I would also prefer to quote a patch here, but for now:
Open TUManager.cpp (which will be in the downloaded irony-mode package), and change
if (CINDEX_VERSION < 6) {
to
if (true) {
This does mean slower completions but it will perhaps remove the assertion failure. If you are not working on a huge project it may be fine.
Recompile irony-server.
Recently I have discovered that if you use driver-mode=cl
and you are using .h
files in your C++ project then you must issue the Tp
flag (not even the TP
flag - as clang will not accept this variant). Also, it should be added at the bottom of the .clang_complete file. I.e. you cannot apply it after --driver-mode=cl
.
For more information that covers everything in the WIKI, visit the already linked link: https://github.com/Sarcasm/irony-mode/issues/280