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

is not a class or namespace name

I know this question has been asked and answered before, but none of the solutions seem to have worked for me, and my compiler is acting really weird with this error. When I try and compile my code I get numerous errors such as these: Error 1 …
Nick Taylor
  • 153
  • 1
  • 1
  • 7
7
votes
1 answer

Precompiled headers

What exactly is precompiled headers? when are they used?
lital maatuk
  • 5,921
  • 20
  • 57
  • 79
7
votes
2 answers

Precompiled headers and normal includes

When using precompiled headers, does it make a difference (or has a bad effect) when I include a header, which I already have included in the precompiled header, also in a regular header? Or in other words: when I include a header x in another…
Mike Lischke
  • 48,925
  • 16
  • 119
  • 181
7
votes
0 answers

How can I get the full benefit of precompiled headers while using ccache?

My project sometimes benefits from ccache, so I have long been using ccache. I'm now adding precompiled headers. Some sources suggest that the two are incompatible and that one must choose between them. But I find in ccache's documentation that…
mjwach
  • 1,174
  • 2
  • 9
  • 25
7
votes
1 answer

How to use .h.gch files

I recently found out about precompiled headers in C++, specifically for gcc compilers. I did find something about the .h.gch files on the net, but haven't yet been able to use them. I need to know: How to create a .h.gch file? My code isn't…
zhirzh
  • 3,273
  • 3
  • 25
  • 30
7
votes
2 answers

Collect common includes in a single file - good practice?

I am trying to learn how to deal with a lot of includes, and still keep my code tidy. I am programming a Qt application and I have put files commonly used (and that doesn't change) in a file called "Util.h". Util.h #pragma once #include…
Adelost
  • 2,343
  • 2
  • 23
  • 28
7
votes
1 answer

Using /YC and /MP together in a Visual Studio 10 project

I'm trying to get around the limitation of /YC and /MP being mutually exclusive. I'd like to leverage precompiled headers AND multi-process compilation. My answer so far has been to create 2 projects instead of 1. The first is a pch generating…
cppguy
  • 3,611
  • 2
  • 21
  • 36
7
votes
2 answers

How to use precompiled headers in Qt project

My IDE: Visual Studio 2010, I use Qt add-in for VS, Qt ver. 4.8.1 I have faced with the problem while trying to create precompiled header(pch) in my Qt project. My usuall approach for creating pch in non Qt project is: Create header; Include files…
spin_eight
  • 3,925
  • 10
  • 39
  • 61
6
votes
4 answers

How does precompiled header reduce compile time

I've been using precompiled header for a while and been told (and saw) how they can reduce compile time. But I would really like to know what is going on (under the hood) so it can make my compilation faster. Because from what I know, adding unused…
Drahakar
  • 5,986
  • 6
  • 43
  • 58
6
votes
0 answers

Why is using precompiled headers on GCC slower

I've tried using precompiled headers with GCC to speed up one of my builds. It is a project with around 80 files, most of which include a single header, which I precompiled. This header includes a large number of other headers. At least on paper…
Sander Mertens
  • 909
  • 8
  • 14
6
votes
5 answers

stdafx.h cross platform without issues?

Hey i've been following learncpp.com tuts for the last couple days, they say to comment out "#include "stdafx.h" from .cpp files for Code::Blocks. Is that a must, to remove the include line? What happens if you had hundreds of files and changed from…
iarp
  • 546
  • 1
  • 9
  • 20
6
votes
3 answers

Comprehension issue: Precompiled headers & include usage

I got a comprehension issue about precompiled headers, and the usage of the #include directive. So I got my "stdafx.h" here and include there for example vector, iostream and string. The associated "stdafx.cpp" only includes the "stdafx.h", that's…
user4655569
6
votes
2 answers

Should I, or should I not include the same headers in different c files, which in turn are headers used in a main file?

I'm building a main.c file to make use of functions out of a few different .h files. A few of those .h files (or rather, their .c source files) use the same includes (the standard but also some others like ) My question is: Is it okay if I just…
Guinn
  • 1,355
  • 13
  • 29
6
votes
3 answers

Need some clarification on #pragma once

I've searched all over for some clarification on what #pragma once actually does and can't find definitive answers for some questions I still have. Does #pragma once insure that the header file it is included in is only called once AS WELL…
6
votes
1 answer

CMake (cotire) precompiled headers and disable warnings

I'm using cotire(https://github.com/sakra/cotire) plugin for CMake, which handles several nice things related to compilation speedup(for example precompiled headers). The problem is that I include several headers (Boost related or Protobuf) as…
Dejwi
  • 4,393
  • 12
  • 45
  • 74