源程序和编译单元之间的区别。 [英] Difference between Source program and Compilation Unit.

查看:89
本文介绍了源程序和编译单元之间的区别。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

详细解释编译单位以及

单独和独立编译之间的区别。

Explain in detail about compilation Unit and also
difference between
separate and independent compilation.

推荐答案

请参阅 http://en.wikipedia.org/wiki/Single_Compilation_Unit [ ^ ]。


没有差异这样的概念。如果你没有看到它,试着告诉我们苹果和苹果之间的区别。最好避免差异问题,只要对你感到困惑的每个概念提出问题。



此外,没有源程序这样的概念。有源代码之类的东西。至于编译单元,这个概念与源代码和编译代码之间的二分法正交。编译单元是基于单独编译的思想的单元。无论您考虑什么,作为编译结果的单元或单元的源代码,您可以考虑单元的一个或两个方面。我希望很清楚。



这是个主意。在某些语言类中,您可以在一个文件或一组文件中包含一些源代码,这些文件可以是编译器,而无需使用项目的其他文件。在C ++中,这可以是.cpp文件以及使用 #include 指令直接或间接包含在其中的所有文件。编译结果生成目标文件。现在,重点是,如何把它们放在一起?该技术基于在编译中具有一些未解析符号的可能性。例如,某些函数可以以声明的形式编写,而不包含定义。通常,此类声明放在头文件中,该头文件可包含在多个单元中。仍然可以成功编译这样的单位,假设定义可以在其他单位或中找到。



另一个程序叫做链接器获取所有已编译的单元并尝试将它们链接在一起。在链接器的输入上,可以添加一些其他目标文件,例如,第三方没有源代码提供,以及对象库(也称为静态库)。如果完全解析了所有外部名称,则链接将生成可执行文件(包括DLL或共享对象(* NIX名称)),否则将发出链接器错误。 />


请参阅:

http:// en .wikipedia.org / wiki / Compiler [ ^ ] ,

http://en.wikipedia.org/wiki/Linker_%28computing%29 [ ^ ],
http://en.wikipedia.org/wiki/Object_file [ ^ ],

http://en.wikipedia.org/wiki/Library_%28computing%29 [ ^ ]。



前两个链接引用的文章,你可以看到显示构建过程的图表和编译器和链接的角色,输入的内容和输出中产生的内容,说明了我的描述。



-SA
There is no such concept as "difference". If you don't see it, try to tell us the difference between apple and Apple. Better avoid "difference" questions, just ask questions on each of the concept you feel to confuse.

Also, there is no such concept as "source program". There is such thing as "source code". As to "compilation unit", this concept is orthogonal to the dichotomy between source and compiled code. Compilation unit is a unit based on the idea of separate compilation. It does not matter what do you consider, source code for the unit or the unit as a result of compilation, you can consider either one, or both aspects of the unit. I hope it's clear.

Here is the idea. In some class of languages, you can have some source code in one file or set of files which can be compiler without using other files of your project. In C++, this can be a .cpp file and all files included in it using #include directive, directly or indirectly. The result of compilation makes an object file. Now, the point is, how to put it all together? The technique is based on the possibility to have some unresolved symbols in the compilation. For example, some function can be written in the form of declaration, without the definition. Typically, such declaration is put in a header file which can be included in more than one unit. Still, such unit can be successfully compiled, assuming that the definition could be found in some other unit or a library.

Another program called linker takes all the compiled units and tries to link them together. On input of linker, some other object files can be added, for example, provided without source code by 3rd parties, as well as object libraries (also called static libraries). If all the external names are resolved altogether, the linkage produces executable files (which include DLLs or shared objects (*NIX name)), otherwise linker error is issued.

Please see:
http://en.wikipedia.org/wiki/Compiler[^],
http://en.wikipedia.org/wiki/Linker_%28computing%29[^],
http://en.wikipedia.org/wiki/Object_file[^],
http://en.wikipedia.org/wiki/Library_%28computing%29[^].

In the articles referenced by first two links, you can see the diagrams showing the build process and the role of a compiler and a linked, what goes on input and is produced in output, illustrating my description.

—SA


这篇关于源程序和编译单元之间的区别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆