C++ 中的编译过程

发布于 2024-09-24 04:11:49 字数 260 浏览 3 评论 0原文

如果有人能真正解释当我按下 BUILD 按钮时我的编译器到底做了什么,并且编译器开始编译我所有的 .h 和 .cpp 文件,这个过程到底是如何进行的(我的目标文件里面有什么),我将非常感激?),我为什么要问这样的问题?我试图理解 Meyers 书中关于 50 种具体方法的“最小化文件之间的编译依赖关系”是什么意思...(希望你了解这本书),他在那里解释了抽象基类和句柄类是什么意思,正如我的讲师向我解释的那样,我不需要包含过多的 .h 文件,仅此而已,任何有关编译过程的链接也将不胜感激,提前感谢您的帮助

I will be very grateful, if somebody can actually explain what exactly my compiler does when I press button BUILD, and compiler begins to compile all my .h and .cpp files how exactly this process is going on(what do I have inside object file?), why do I ask such question? I'm trying to understand what does it mean "minimize compilation dependencies between files" from book of Meyers about 50 specific ways...(hope You know about this book),there he explains what does it mean Abstract Base Class and Handle Classes, as my lecturer explained me I don't need to include excessive .h files and thats all, any links about compilation process will be appreciated as well, thanks in advance for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

御守 2024-10-01 04:11:49

在进行完整编译时,编译器将依次读取每个.cpp 文件。对于给定的 .cpp 文件,它将递归地读取 #include 指令引用的每个文件,并编译代码。当它编译下一个源文件时,它将读取该源文件中用 #include 引用的文件。

当您进行任何更改并进行构建时,如果 .cpp 文件中的 #include 指令引用的任何文件已更改,则 .cpp 文件将被重新编译,就像 .cpp 一样文件本身已更改。

因此,不必要的 #include 指令有两个成本:首先,编译器在编译时必须读取和处理更多文件,其次,它增加了 .cpp 文件需要重新编译的机会,即使它实际使用的任何内容都没有。改变了。

When doing a full compile, the compiler will read each .cpp file in turn. For a given .cpp file it will then read every file referenced by a #include directive, recursively, compiling the code as it goes. When it compiles the next source file it will read the files referenced with #include in that source file.

When you make any changes and do a build, then if any of the files referenced by a #include directive from your .cpp file have changed then the .cpp file will be recompiled, as if the .cpp file itself has changed.

Unnecessary #include directives thus have two costs: firstly the compiler has to read and process more files when compiling, and secondly it increases the chances that your .cpp file will need recompiling even if nothing it actually uses has changed.

帅气称霸 2024-10-01 04:11:49

请参阅

http://computer.howstuffworks.com/c2.htm
了解简介和

http://www.tenouk.com/ModuleW.html
如需深入描述

此外,可以在以下位置找到一些理论背景:
http://en.wikipedia.org/wiki/Compiler

See

http://computer.howstuffworks.com/c2.htm
for a introduction and

http://www.tenouk.com/ModuleW.html
for an in depth descirption

Additionally, some theoretic background can be found at
http://en.wikipedia.org/wiki/Compiler

汹涌人海 2024-10-01 04:11:49

了解编译器如何工作的最好方法是首先了解汇编器如何工作。这里有一个不错的解释

The best way to understand how a compiler works is to first understand how an assembler works. There is a decent explanation here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文