

Precompiled headers in C/C++
source link: http://codeforces.com/blog/entry/97704
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

By ilia_rr, 9 hours ago,
Hi everybody!
This blog is about speeding up C/C++ compilers with precompiled headers.
Including lots of headers or big headers like bits/stdc++.h
will increase compilation time. This can be annoying even with high speed processors. We can solve this using precompiled headers.
What are precompiled headers?
You can compile a header like stdc++.h
to stdc++.h.gch
and compiler will use it instead of compiling the header every time you are compiling your code. Less processing => Less time.
How to use precompiled headers?
Find your g++ default include directory
- Ubuntu:
/usr/include/x86_64-linux-gnu/c++/{version}
- Windows:
C:\MinGW\lib\gcc\mingw32\{version}\include\c++
- Ubuntu:
Compile headers you need (I recommend using
bits/stdc++.h
instead of including lots of headers).g++ {header name} {flags you use when compiling a normal code}
Put .gch files in the right place. You have 2 Options:
- Put them in the directory you find the headers & use
#include <header name>
- Put them in your code directory & use
#include "header name"
I recommend first options because the second one will work only when .gch files are in the code directory and it takes a little extra time to search in code.
- Put them in the directory you find the headers & use
Compile a code and feel the difference!
Comment your issues or suggestions.
Be good and code fast ;)
Recommend
-
88
lambda-packs Precompiled packages for AWS lambda How to start https://aws.amazon.com/lambda/ and create/sign in into account Lambda > Functions...
-
136
vim-header Easily adds brief author info and license headers Table of Contents Install Preferred installation method is Pathogen ...
-
40
README.md
-
31
In this article we’ll talk about one of the recent GraalVM updates, libgraal . It’s a shared library, produced by
-
31
Modules are coming in C++20 but it will take a while before they are widely adopted, optimized and supported by tooling - what can we do right now ?
-
8
libmobilecoin-ios-artifacts MobileCoin is a privacy-preserving payments network designed for use on mobile devices. Sending your First Payment You must read and accept the
-
4
using serde_derive without precompiled binary #2538 Closed ...
-
5
Rust Users Push Back as Popular 'Serde' Project Ships Precompiled Binaries
-
6
Conversation Contributor Follow...
-
4
Precompiled headers C/C++ projects can benefit from using precompiled headers to improve compile time. GCC
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK