开发者

precompiled Headers C++

开发者 https://www.devze.com 2023-03-15 19:38 出处:网络
assume We have c++ project (static)library \'A\' that uses DirectX headers as precompiled headers to implement base graphic engine.

assume

We have c++ project (static)library 'A' that uses DirectX headers as precompiled headers to implement base graphic engine.

and we have project (static)library 'B' that uses 'A' headers as precompiled headers to implement game engine

and we have c++ project 'C' that uses two previous projects to implement a game

now my question is:

is there any way for开发者_如何学Python project 'C' to just include project 'B' and do not include (DirectX headers and 'A' headers)?

or on the other hand

is there any way to embed (DirectX and project 'A') to project 'B'?

tanks


Just make sure that the project B has some clean interface headers that expose the functionality of the game engine that can be used from the C modules without giving any details how they are implemented. Those may be abstract classes or follow the convention of interfaces. And they should be all what is required to be included by C. All DirectX stuff can be located in private files that are not intended for external use.


Precompiled headers should NEVER be exposed to users of a library. They are a detail of the implementation of a library; nothing more. PCHs are something that .cpp files include; they should never be included from a header file.

Remember: a header file should include only what that header file absolutely needs to in order for it to compile.

Let's take your example. Project A uses DirectX. Therefore, the .cpp files in Project A include a PCH that includes the DirectX headers. Now, if the interface to Project A uses DirectX objects and types, then the Project A interface headers (the ones used by users of Project A) will need to include the DirectX headers.

This will not affect the ability of Project A to use a PCH to improve compile times. The DirectX headers have include guards, so they will not be included multiple times. It costs nothing to include them in the interface headers of Project A.

Project B, which uses Project A, will have its own PCH files. This PCH will include DirectX and Project A's headers. Therefore, the inclusion of DirectX in Project A's headers will not affect the build time of Project B.

Project B uses Project A. But, as you have described it, Project B does not expose any users of Project B to Project A or DirectX. That is, the fact that Project B uses Project A is an implementation detail of Project B, and therefore it should not be exposed to users of Project B.

As such, Project B's interface headers (the headers used by users of Project B) do not include anything from Project A or from DirectX. Therefore, this Project C which uses Project B will not include them.


Since B project includes/links with project A, there is no need to include 'A' in project 'C'. Project B would have all stuff that is in project A, and project C would therefore contain all of A and B.

0

精彩评论

暂无评论...
验证码 换一张
取 消