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
14
votes
1 answer

How to make GCC search for headers in a directory before the current source file's directory?

I am using GCC precompiled headers in my project with multi-architecture build, but things break down when I try to place it in a directory different from current source's directory. The file is included with double quotes, and it works if I change…
Alex B
  • 82,554
  • 44
  • 203
  • 280
14
votes
7 answers

Precompiled Headers? Do we really need them

Back a long time ago I used to use pre-compiled headers: a. to speed compilation and b. because I supported multiple development tools like CodeWarrior, MPW, VS, ProjectBuilder, gcc, intel compilers, etc, etc. Now I have a Mac Pro with 32gb of RAM.…
Todd
13
votes
2 answers

cc1plus.exe crash when using large precompiled header file

I'm having an issue using precompiled header files with MinGW. The compiler seems to find the precompiled header file but cc1plus.exe crashes immediately after (cc1plus.exe has stopped working). I've understood that this might be in connection with…
jadam
  • 131
  • 1
  • 3
11
votes
2 answers

Precompiled header errors in Visual Studio 2022 version 17.6

I have a Visual Studio C++ project, and after updating Visual Studio 2022 recently from version 17.5 to version 17.6, the compilation stops in the very beginning with the error: 1>------ Rebuild All started: Project: MRPch, Configuration: Debug x64…
Fedor
  • 17,146
  • 13
  • 40
  • 131
11
votes
3 answers

What does #pragma hdrstop without parameter do when used in multiple files?

What is the practical value ("what does it do") of putting #pragma hdrstop (no filename parameter) in a couple of source (cpp) files? Note that the MSDN docs are (once again) as clear as mud to me. Edit/Note: I'm asking this, because this answer and…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
11
votes
3 answers

Will instantiating templates in precompiled headers reduce compile times?

Example: Say I include in my precompiled header file: #include As a few instances of the vector, such as std::vector, std::vector etc are used often in my project, will it reduce compile time if I instantiate them as well in the…
Viktor Sehr
  • 12,825
  • 5
  • 58
  • 90
11
votes
5 answers

C3859: Virtual memory range for PCH exceeded

I get this error message from time to time (not every time) I compile (EDIT: sorry, I didn't make myself clear here: I actually meant "rebuild") my mixed-mode project. And Visual Studio tells me to "recompile with a command line option of '-Zm114'…
11
votes
4 answers

Why does stdafx.h work the way it does?

As usual, when my brain's messing with something I can't figure out myself, I come to you guys for help :) This time I've been wondering why stdafx.h works the way it does? To my understanding it does 2 things: Includes standard headers which…
Meeh
  • 473
  • 2
  • 7
  • 13
11
votes
5 answers

How do I eliminate error C2859 when trying to use a precompiled header with VS2010 (VC100) in debug mode?

I am trying to upgrade an old solution to use VS2010 (VC100). I have it setup so that stdafx.cpp will create a precompiled header stdafx.pch from stdafx.h. Then all the other .cpp files that include stdafx.h are instructed to use the precompiled…
steinybot
  • 5,491
  • 6
  • 37
  • 55
11
votes
9 answers

Is there a way to use pre-compiled headers in VC++ without requiring stdafx.h?

I've got a bunch of legacy code that I need to write unit tests for. It uses pre-compiled headers everywhere so almost all .cpp files have a dependecy on stdafx.h which is making it difficult to break dependencies in order to write tests. My first…
Ferruccio
  • 98,941
  • 38
  • 226
  • 299
10
votes
3 answers

Uncompile a gch file

I accidentally removed a .h file I hadn't added to version control, but I still have the .h.gch. Is there any way to uncompile the .gch?
Aaron Yodaiken
  • 19,163
  • 32
  • 103
  • 184
10
votes
1 answer

Why doesn't g++ find the precompiled-header that's in the -I include-path?

I'm trying to build a precompiled header and an executable, like so: g++ -g -Wall -std=c++17 \ -c ./src/pch.hpp -o ./build/pch.hpp.gch g++ -g -Wall -std=c++17 \ -c ./src/*.cpp \ -I./build/ -include pch.hpp The pch.hpp.gch file…
nihohit
  • 498
  • 3
  • 23
10
votes
2 answers

How to use precompiled headers efficiently (using /Yc and Yu options)?

We are using Visual Studio 2003 (VC71) for compilation. In order to reduce the compile time we changed the build script such that it generates the precompiled header (.pch) file for each CPP file. The option used in…
aJ.
  • 34,624
  • 22
  • 86
  • 128
10
votes
2 answers

Is there a cleaner way to handle compiler errors C1076 and C3859?

Today I've been adding some library headers to our precomp.h file. Then I tried to recompile in debug and got those two errors (spawned from a boost include): error C3859: virtual memory range for PCH exceeded; please recompile with a command line…
Vaillancourt
  • 1,380
  • 1
  • 11
  • 42
10
votes
4 answers

C++ Do I have to include standard libraries for every source file?

I'm a bit confused at the moment because I'm planning to include multiple source and header files for the first time in one of my projects. So I'm wondering if this would be the right approach? Do I have to include the string header in every source…
Forivin
  • 14,780
  • 27
  • 106
  • 199
1 2
3
30 31