Questions tagged [precompiled-headers]

A precompiled header is a header file that has statically compiled but still separate from its final executable in order to speed up compilation of dependent files.

In C and C++, precompiled headers allow for quicker compilation times by keeping the definitions from a given header in an compiled state. This allows the compiler to quickly incorporate the header when a file dependent on the header is being compiled.

Rather than having to parse through code, precompiled headers allow the compiler to skip directly to a more intermediate state. For headers that are used frequently this can result in significant compile-time savings.

454 questions
26
votes
6 answers

What are the pros & cons of pre-compiled headers specifically in a GNU/Linux environment/tool-chain?

Pre-compiled headers seem like they can save a lot of time in large projects, but also seem to be a pain-in-the-ass that have some gotchas. What are the pros & cons of using pre-compiled headers, and specifically as it pertains to using them in a…
Catskul
  • 17,916
  • 15
  • 84
  • 113
25
votes
5 answers

Precompiled Headers with Mixed C and C++

I am using pre-compiled headers in my project in C but we are integrating a .CPP file into the project. Here's the error: Error 1 fatal error C1853: 'Debug\MuffinFactory.pch' precompiled header file is from a previous version of the compiler, or…
James Linden
  • 1,055
  • 3
  • 11
  • 21
24
votes
4 answers

How to implement precompiled headers into your project

I understand the purpose and reasoning behind precompiled headers. However, what are the rules when implementing them? From my understanding, it goes something like this: Set your project up to use precompiled headers with the YU…
Chris
  • 21,549
  • 25
  • 71
  • 99
23
votes
2 answers

What is the best practice for using precompiled headers in a modern C++Builder application?

I am currently migrating a large RAD Studio 2010 project to XE4. As part of this, I am recreating many of the project files. I would like to take the opportunity to ensure we are using the best possible mechanism for precompiled headers, since there…
David
  • 13,360
  • 7
  • 66
  • 130
20
votes
2 answers

What is the difference between "Create Precompiled Header" (/Yc) and "Use Precompiled Header" (/Yu) in Visual Studio?

I read the documentation in MSDN, but in the end I didn't get a clear idea what is the practical difference between them, exactly. Both seem to require stdafx.h to be added at the top of every *.cpp file. I'm using VS2008. Can anyone help clear…
19
votes
5 answers

GCC build time doesn't benefit much from precompiled headers

I have a huge project, something about 150 000 LOC of C++ code. Build time is something about 15 minutes. This project consists of many sub-projects of different sizes. I have built separate precompiled headers for each subproject, but when I use…
Evgeny Lazin
  • 9,193
  • 6
  • 47
  • 83
18
votes
4 answers

Visual Studio 2010, Intellisense and PCH: what are the alternatives to ugly stdafx.h?

I recently switched to Visual Studio 2010 and for Intellisense not to take half a minute to show up when using boost libraries, Microsoft's suggestion seems to use precompiled headers. Except that I never used them before (except when forced to by…
Alexandre C.
  • 55,948
  • 11
  • 128
  • 197
18
votes
2 answers

How do I add a precompiled header file to my ios project?

I'm looking to create a precompiled header file, to avoid having to include the same debug and tracking libraries in every header in the project. I've created a file called -Prefix.pch: #ifdef __OBJC__ #import "Blah.h" #import "Blarg.h" #endif and…
blueberryfields
  • 45,910
  • 28
  • 89
  • 168
17
votes
1 answer

How to use precompiled headers in Android NDK project?

I'm porting a big C++ project from Visual Studio to GCC for Android. Because of the large number of files, the compile times are glacial. I would like to setup a precompiled header file, but I find the GCC documentation confusing. I have the…
Meh
  • 7,016
  • 10
  • 53
  • 76
17
votes
2 answers

Speed up compilation/link time when using boost libraries

I'm using Boost Program Options, and it takes quite a while (10 seconds or even more) for compiling very small C++ code with it. It took 1 second compiling the code without boost library. Any idea how to boost compilation/link time with boost…
prosseek
  • 182,215
  • 215
  • 566
  • 871
15
votes
2 answers

include stdafx.h in header or source file?

I have a header file called stdafx.h and this one is precompiled of course. I've read that I should include these files into my .cpp files, but some of these statements are already needed in the header file coming with that. Should I add the stdafx…
Marnix
  • 6,384
  • 4
  • 43
  • 78
15
votes
4 answers

Visual C++ Precompiled Headers errors

Update: What are the effects of including stdafx.h in my header files? I started on a C++ project in Linux/Eclipse CDT and imported it into Visual C++/Windows. In Visual C++, I started using precompiled headers to speed up compilation and defined…
jameszhao00
  • 7,213
  • 15
  • 62
  • 112
15
votes
3 answers

Precompiled Headers in Header Files

I ran into precompiled headers today for the first time..forever changing my life. I can't believe compiling my C++ code could be that fast. It makes total sense now.. Anyway, one thing that is confusing me is that from what I've read so far,…
irwinb
  • 993
  • 2
  • 10
  • 20
14
votes
3 answers

gcc precompiled header: pragma once in main file

I created a header file. Something simple as follows. #pragma once #include template void say(T t) { std::cout << t << std::endl; } and then use g++ to create the gch pre-compiled header with g++ hello.h. It gives me…
Mochan
  • 1,329
  • 1
  • 13
  • 27
14
votes
3 answers

How to make clang -E omit precompiled header

PrecompiledHeader.h: #include "stdio.h" main.cpp: #include "PrecompiledHeader.h" #include "stdio.h" int main() { return 123; } Creating precompiled header: clang -x c++-header PrecompiledHeader.h -o PrecompiledHeader.pch Running clang…
Lucas Meijer
  • 4,424
  • 6
  • 36
  • 53
1
2
3
30 31