Can precompiled headers be used with generated MIDL files?

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

Can precompiled headers be used with generated IDL files? How can I insert #include "stdafx-h"

and remove other included headers?

+2


source to share


2 answers


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

It will not remove other headers, but it is not necessary to use Precompiled Header ... All headers you want to precompile must be included in stdafx.h. Then, if the files have include defenders, it won't be a problem if they are included in sources again.

Example

Generated file a.cpp

:



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

      

Let's say you want to precompile a.h

and b.h

. Then you create the stdafx.h file:

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

      

And then you use the / FI option to have this stdafx.h included as the first file in the a.cpp

. If the files a.h

and b.h

have included guards , leaving them a.cpp

is not a problem ...

+1


source


"stdafx.h" is just a convention. If you know that the source files you create always have the standard include headers prefix, you can name the last one in /Yu

(use precompiled headers). To create a PCH, create one .cpp file with only those fixed headers and compile me with /Yc

.



0


source







All Articles