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
3
votes
3 answers

what is the most unobtrusive way of using precompiled headers in Visual C++?

Say I have a single project, with files A.cpp, B.cpp, C.ppp and matching header files (and that's it). The C++ files include system headers or headers from other modules. I want to compile them to a library with command line actions (e.g., using…
IttayD
  • 28,271
  • 28
  • 124
  • 178
3
votes
2 answers

Multiply Defined Symbols with Precompiled Header?

Well, I have been struggling with this for days now. I am writing a custom game DLL for CryENGINE from scratch, and I cannot even get the solution compile with one simple class (Game.cpp) and a precompiled header (StdAfx.h). Both Game.cpp and…
3
votes
1 answer

"warning C4350: behavior change" when including and no precompiled header

Warning C4350 says "A non-const reference may only be bound to an lvalue". I think since C4350 is off by default I haven't found much out there on it. I have read this post and it makes sense: Non-const reference may only be bound to an…
Jacob
  • 410
  • 3
  • 11
3
votes
1 answer

c++ precompiled header defined in a header VS2010. Compiler can't find

I've inherited some code that did something like this, Header: HeaderFile.h #ifndef HEADERFILE_H #define HEADERFILE_H #ifndef…
Dan
  • 2,625
  • 7
  • 39
  • 52
2
votes
2 answers

In GCC, can precompiled headers be included from other headers?

When I compile a c++ file that includes a precompiled header, everything works as expected // test.c++ #include #include main() {} > g++-4.7 --std=c++11 BLAH... test.c++ -H 2>&1 | grep precompiled.h !…
Casey Rodarmor
  • 14,878
  • 5
  • 30
  • 33
2
votes
5 answers

Structs inside #define in C++

Being pretty new to C++, I don't quite understand some instructions I encounter such as: #ifndef BOT_H_ #define BOT_H_ #include "State.h" /* This struct represents your bot in the game of Ants */ struct Bot { State state; Bot(); …
Jumbala
  • 4,764
  • 9
  • 45
  • 65
2
votes
1 answer

Compilation speed improvements include guards vs. precompiled headers

I want to reduce compile time on a large project. Our primary compiler is Visual Studio 2010 but some of the code gets compiled in gcc. We are currently planning to ensure that all our .h files have both include guards as well as #pragma once,…
2
votes
1 answer

How to change .pch file location(Visual Studio 2008)?

my project has a lot of pch files. So, when I build projects, it makes .pch files a lot at Local\Temp\c\Vs2008... Because I have small capacity harddisk, I want to change the destination of .pch file generated. How to change .pch file location? I…
P-P
  • 1,670
  • 5
  • 18
  • 35
2
votes
1 answer

How to do use precompiled headers with gcc and make?

I have a make file that uses the -MMD -MP options when invoking g++. This creates the .d dependency files that look something like this: blah.o: header1.h header2.h Now, I'm trying to add precompiled header support, and would like to have a rule…
user545226
  • 103
  • 1
  • 8
2
votes
2 answers

How to create precompiled header with codeblocks and gcc

I have a file which has been tested and works as intended: #ifndef PROMOTE_H_INCLUDED #define PROMOTE_H_INCLUDED #include #include #include #include…
smallB
  • 16,662
  • 33
  • 107
  • 151
2
votes
1 answer

Pre-compiled header warnings on Linux (too short to be a PCH file)

I have a header in my project, called Core.h, that I use as a pre-compiled header: $(CXX) $(CXX_CFLAGS) -x c++-header Core.h Which creates a file named Core.h.gch *#include "Core.h" is the first directive of every source file in the module. On OS…
zedxz
  • 113
  • 1
  • 8
2
votes
0 answers

How can I speed up compile times when developing a Clang-based tool?

I'm developing a Clang-based tool (i.e., a ClangTool), but the time to recompile a source file is longer than I would like. Specifically, for the small example program below, it takes about 7 seconds to compile this one file, and I've only #included…
Scott McPeak
  • 8,803
  • 2
  • 40
  • 79
2
votes
4 answers

How to Precompile header file in ubuntu 20.04 / 22.04?

Is there any way to precompile the header file in ubuntu 20.04 like we can do in Windows OS so that I can execute programs faster in my Sublime text editor? I use the FastOlympicCoding extension for fast execution, but I miss the old…
princebansal_
  • 133
  • 3
  • 9
2
votes
1 answer

How to know if compiler is taking advantage of the pch.h.gch file?

Is there a way to check to see if GCC uses the precompiled header or not? Also, I generate pch.h.gch file like this: g++ -std=c++20 -Wall -O3 -flto pch.h -o pch.h.gch But the generated file is always named as pch.h and without the .gch extension.…
digito_evo
  • 3,216
  • 2
  • 14
  • 42
2
votes
0 answers

How to add precompiled header to VS Code?

Is it possible to add precompiled header for C++ in Visual Studio Code, and if so, how? Couldn't find info anywhere.
softcactus
  • 31
  • 2