Home > Archive > VC Language > June 2005 > Using precompiled headers with C and C++
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Using precompiled headers with C and C++
|
|
| Mark Ingram 2005-06-07, 4:05 pm |
| Hi,
Ive got a project which contains mixes of C and C++, and before you
suggest renaming the files, i cant ;).
Basically, i need a way of speeding up the compile time because its
horrendously slow, for our C++ projects, precompiled headers are a godsend.
Ive tried creating the following header file (incorrectly):
// C Includes
#if !defined(__cplusplus)
extern "C"
{
#include "main.h"
#include "error.h"
#include "acorn.h"
#include "pri.h"
#include "gra.h"
#include "car.h"
#include "mod.h"
#include "win.h"
#include "vie.h"
}
#endif
// C++ Includes
#if defined(__cplusplus)
#endif
But obviously, as this is always included from StdAfx.cpp it will always
be compiled as a C++ header.
So, how can i get my C files to include this precompiled header
successfully?
Any help on this would be much appreciated!
Cheers
| |
| Sergei 2005-06-07, 4:05 pm |
| "Mark Ingram" <mark.ingram@removeme.softease.com> wrote:
> Hi,
>
> Ive got a project which contains mixes of C and C++, and before you
> suggest renaming the files, i cant ;).
>
> Basically, i need a way of speeding up the compile time because its
> horrendously slow, for our C++ projects, precompiled headers are a godsend.
>
> Ive tried creating the following header file (incorrectly):
>
> // C Includes
> #if !defined(__cplusplus)
> extern "C"
> {
> #include "main.h"
> #include "error.h"
> #include "acorn.h"
> #include "pri.h"
> #include "gra.h"
> #include "car.h"
> #include "mod.h"
> #include "win.h"
> #include "vie.h"
> }
> #endif
>
> // C++ Includes
> #if defined(__cplusplus)
> #endif
>
>
> But obviously, as this is always included from StdAfx.cpp it will always
> be compiled as a C++ header.
>
> So, how can i get my C files to include this precompiled header
> successfully?
Why not use two header files?
Sergei
> Any help on this would be much appreciated!
>
> Cheers
| |
| Mark Ingram 2005-06-07, 4:05 pm |
|
>
>
> Why not use two header files?
>
> Sergei
I think ive sorted it now, ive got:
StdAfx.h
StdAfx.c
StdAfx.cpp
Then depending on whether its a C or C++ file, i choose the correct
precompiled header file to use. Seems to work ok so far - unless anyones
got any better suggestions!
Thanks
| |
| Sergei 2005-06-07, 4:05 pm |
| "Mark Ingram" <mark.ingram@removeme.softease.com> wrote:
>
>
> I think ive sorted it now, ive got:
>
> StdAfx.h
> StdAfx.c
> StdAfx.cpp
>
> Then depending on whether its a C or C++ file, i choose the correct
> precompiled header file to use. Seems to work ok so far - unless anyones
> got any better suggestions!
This should work if you precompile them to different pch files.
Though I would expect different .h files as well.
Sergei
|
|
|
|
|