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

Can I share a precompiled header between projects to reduce compile time?

I have nearly 200 projects in Visual Studio and it takes too long to build them all. I notice that building stdafx.cpp (the precompiled headers) for each project is slow. I'm using the same header for every project, so why do I have to build it ~200…
David
  • 1,023
  • 1
  • 8
  • 16
6
votes
1 answer

No speedup with precompiled headers on gcc (but large speedup with visual studio)

I'm working on a large project that must builds under multiple environment, chiefly linux/gcc and windows/msvc. To speed up the build, we use precompiled headers. The Windows implementation is very efficient: on my quad-core hyperthreaded i7 build…
Norswap
  • 11,740
  • 12
  • 47
  • 60
6
votes
1 answer

GCC and Precompiled Headers

After reading this nice article (The Care and Feeding of Pre-Compiled Headers), I have some doubts regarding how these can actually work in real life. More specifically, how can I know that I need to trigger the rebuild of the pre-compiled header in…
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
6
votes
3 answers

Why building a DLL without precompiled headers causes a weird error when used?

In summary: Today I discovered that when a DLL is built without precompiled headers, a strange error shows when you try to use it. Building the DLL goes fine when precompiled headers are disabled. However as soon as the DLL is attached (either…
Bart
  • 1,633
  • 14
  • 21
5
votes
0 answers

What does this compiler warning mean? "had text segment at different address"

I'm cross compiling a project on a Mac running Lion, using GCC for an ARM target. I'm using precompiled headers and getting this warning for every object that compiles against my PCH: cc1plus: warning: /yada/yada/yada_afx.hpp.gch: had text segment…
5
votes
1 answer

Cmake target_precompile_headers leads to redefiniton errors

When using Cmakes target_precompile_headers we get a lot of redefinition errors like /usr/include/c++/8/bits/stringfwd.h:70:37: error: redefinition of default argument for ‘class _Traits’ /usr/include/x86_64-linux-gnu/bits/types/__mbstate_t.h:21:3:…
TPandia
  • 51
  • 4
5
votes
3 answers

Visual Studio deletes a shared .pch file, and questions about custom build steps

I try to use a shared .pch file, which is compiled in one project and used in others. However the .pch file is deleted if a .pdb filename of the PCH project differs from .pdb filenames of the other projects. This page doesn't answer the question:…
5
votes
2 answers

How to fix 'PCH Warning: header stop not at file scope'

I've set up my programs and header files as what I think is the correct way, but I keep getting the error mentioned in the title. I have tried searching for fixes for this issue, which most of them were simply adding ';' after the class definition…
Stanky-kun
  • 71
  • 1
  • 1
  • 6
5
votes
1 answer

What do Visual Studio's precompiled headers contain?

The question concerns the contents of the .pch binary created by the Visual Studio compiler. What does it contain? Is it only the parsed tree of the header files, or object code as well? Consider this example: // myheader.h #include class…
Viktor
  • 3,295
  • 2
  • 25
  • 26
5
votes
0 answers

Using pragma push in precompiled header with Clang without pop

In my codebase, I have an include file (MyBaseDefinitions.h) that does a pragma diagnostic push followed by disabling a lot of warnings. If you want to re-enable those warnings, you simply include another header afterwards that does pragma…
jvaneenwyk
  • 73
  • 1
  • 5
5
votes
1 answer

C++ precompiled-headers huge in size

I have 2 questions about c++ precompiled-headers feature. 1.What actually is happening when you make a .gch file (using GCC), what it contains ? 2.Why those files are so huge in size , but the final executable is so small.
Ursescu Ionut
  • 97
  • 1
  • 6
5
votes
0 answers

How to disable warnings in specific location?

To disable warnings in all files, i'm using following precompiler header: #ifndef PrefixHeader_pch #define PrefixHeader_pch #ifdef __OBJC__ #import #endif #pragma clang diagnostic ignored "-Wmacro-redefined" #pragma…
Gikas
  • 961
  • 1
  • 8
  • 20
5
votes
2 answers

Setting up a project which would compile both with and without precompiled header

What I am trying to do is to set up a project in which wouldn't matter if precompiled header is set or not. stdafx.hpp is my P.H. My main problem is that I have files over serveral directories, not only project root directory. What have I tryed: If…
5
votes
1 answer

How to benefit most from precompiled headers with gcc?

I have a C++ project with many targets that include a lot of boost header files and other line-intensive headers. Most of the targets include the same headers. Thus, I thought this might be ideal to use precompiled headers (pch). So I created a…
veio
  • 507
  • 4
  • 16
5
votes
5 answers

C++ Precompiled Header Disabled

In Visual Studio 2015, I have a C++/CLI project with the following error: "fatal error C1010: unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?" I turned off precompiled…