Using Precompiled Headers

Asked 2 years ago, Updated 2 years ago, 30 views

I am a beginner developer who has been studying C++ language for almost a year.

If there are more source files during development, the compilation time will eventually increase, and to solve this problem, I want to use a precompiled header.

Precompiled headers should not change frequently. But what about this case?

stdafx.h <- Precompiled header and in that header

include "UserDefine.h"

So I want to define the constant values or enum that I want in the UserDefine header.

UserDefine is a file that changes frequently

Does this also affect stdafx.h?

c++ c

2022-09-22 20:23

1 Answers

It is not recommended to include a header that changes frequently in a precompiled header (pch) because the entire source must be rebuilt whenever that header changes.

In other words, when UserDefine.h is put into the pach, it only adds a line of defines to that header, which leads to unnecessary recompiling of the entire source.

Therefore, it is best to include only external libraries (such as STLs).

Since rebuilding is not expensive for small projects anyway, it doesn't matter if you include various things in the pch for convenience,

In this case, it is better to make a habit of embedding the necessary headers directly into the necessary cpps.


2022-09-22 20:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.