views:

175

answers:

2

We do have a project wich uses the MIDL tool to create specific header/iid and proxy files. Those files are compiled and linked with the rest of the project using a post build step that calls nmake.

Is it possible to use precompiled headers with thos IDL generated files? How can I inject #include "stdafx-h" and remove other included headers?

+1  A: 

Use the /FI option (Force Include): "This option has the same effect as specifying the file with double quotation marks in an #include directive on the first line of every source file specified on the command line, in the CL environment variable, or in a command file."

It won't remove the other headers, but this is not necessary for the Precompiled Header to be used... All the headers that you want to precompile should be included by stdafx.h. Then, provided the files have inclusion guards, it won't be a problem when they are included again in the sources.

Example

Generated a.cpp file:

#include <a.h>
#include <b.h>
//rest of the code

Suppose you want to pre-compile a.h and b.h. Then you create the file stdafx.h:

#include <a.h>
#include <b.h>

And then you use the /FI option to have this stdafx.h included as the first file into a.cpp. If the files a.h and b.h have include guards, leaving them in a.cpp is not an issue...

Xavier Nodet
Wouldn't work - the reason for `#include <stdafx.h>` is to demarcate the point after which normal compilation of the source file resumes.
MSalters
@MSalters Indeed, normal compilation resumes after the inclusion of stdafx.h. But I don't see a problem... Either stdafx.h also includes all the remaining files, and it shouldn't be an issue to include them again, or it doesn't and then why would you want to remove the remaining files?
Xavier Nodet
@MSalters: updated my answer.
Xavier Nodet
+1 for that answer. It did work - all I needed to specify was /FI stdafx.h /Yu"stdafx.h" /Fp".\Debug\moc.pch"\
fmuecke
A: 

"stdafx.h" is merely a convention. If you know that yout generated source files always have a standard prefix of included headers, you can name the last of them in the /Yu switch (use precompiled headers). To create the PCH, create an single .cpp file with just those fixed headers and compile ith with /Yc.

MSalters