为什么编译成目标文件第一? [英] Why Compile to an Object File First?

查看:100
本文介绍了为什么编译成目标文件第一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的一年我在Fortran语言开始编程在研究型大学工作。我的大部分以前的经验是网络语言如PHP或ASP老,所以我是一个新手汇编语句

In the last year I've started programming in Fortran working at a research university. Most of my prior experience is in web languages like PHP or old ASP, so I'm a newbie to compile statements.

我有两个不同的code我修改。

I have two different code I'm modifying.

有一个明确的语句从模块创建.o文件(例如gfortran -c filea.f90)创建可执行文件之前。

One has an explicit statement creating .o files from modules (e.g. gfortran -c filea.f90) before creating the executable.

另一个创建可执行文件直接(有时创建.mod文件,但没有.o文件,如:gfortran -o可执行filea.f90 fileb.f90 mainfile。 F90)。

Another are creating the executable file directly (sometimes creating .mod files, but no .o files, e.g. gfortran -o executable filea.f90 fileb.f90 mainfile.f90).


  • 是否有一个原因(比,也许,Makefile文件等)的一种方法是pferred比其他?
  • $ P $
  • Is there a reason (other than, maybe, Makefiles) that one method is preferred over the other?

推荐答案

编译到目标文件就是所谓独立的编译。有很多优点,并有一些缺点。

Compiling to object files is what is called separate compilation. There are many advantages and a few drawbacks.

优点:


  • 便于以后目标文件(.o)图书馆和链接转换成它们

  • 很多人都可以在同一时间在不同的目标文件的工作

  • 更快编译(你不要再和重新编译相同的文件)

  • 对象文件可以以不同的语言作出,并在稍后的时间联系在一起。要做到这一点的目标文件只需要使用相同的格式和兼容的调用约定。

  • 独立编译使全系统的文库(OS库,语言标准库或第三方库),无论是静态或共享的分配。

缺点:


  • 有一些优化(如优化功能以外)编译器不能执行器和连接器不在乎;然而,许多编译器现在包含选项执行链接时优化,这在很大程度上否定了这一缺点。但是这仍然是系统库和第三方库的问题,特别是对共享库(不可能优化掉可能在每次运行更改组件,然而像JIT编译其它技术可以减轻这种部分)。

  • 在目标文件的某些语言程序员提供某种标题为利用他人将与该对象链接。 (即:用C,你必须提供 .H 文件)。但它是很好的做法反正。

  • 在基于文本的语言包括C或C ++,如果更改一个文件原型你必须在两个地方去改变它。一旦在头文件,一旦执行文件(如果你使用C ++,你也可以在头内联函数的实现,但它不是单独的编译了)。

  • There are some optimizations (like optimizing functions away) that the compiler can't perform and the linker don't care; however, many compilers now include the option to perform "link time optimization", which largely negates this drawback. But this is still an issue for system libraries and third party libraries, especially for shared libraries (impossible to optimize away parts of a component that may change at each run, however other techniques like JIT compilation may mitigate this).
  • in some languages programmer of object file has to provide some kind of header for the use of others that will link with this object. (ie: in C you have to provide .h files). But it is good practice anyway.
  • in languages with text based includes like C or C++, if you change a file prototype you have to change it at two places. Once in header file, once in implementation file (if you use C++ you could also inline function implementation in header, but then it's not separate compilation any more)..

这篇关于为什么编译成目标文件第一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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