关于 Fortran 的非常简单的问题 - UNIX 编译
如果这太天真或太明显了,我深表歉意,但经过一番搜索后,我不能 100% 确定我理解 fortran/unix 界面。我的不确定性在于将 Fortran 程序编译成 unix 可执行文件时遇到的 .src、.f、.o 和 .out 文件的性质。像这样用谷歌搜索文件扩展名是很困难的。但如果你能告诉我我是否明白了这一点,我将非常感激!
.src 是包含丰富的 Fortran 代码的源文件
.f 是“特定于主机语言的包含文件”,它告诉您的 Fortran 编译器一些有关源代码的信息。有时是互动的。
--- 获得 .o 或 .out 文件后,可以扔掉 .src 和 .f 文件,是吗?
.o 是编译但未链接 fortran .f 和 .src 文件所产生的二进制目标文件。它包含相同的肉,但现在转换成机器特定的指令? .out 是链接的目标文件,它是可执行的,并且仍然依赖于 .o 文件,并且是特定于机器的。 .out 文件扩展名实际上并不需要并且经常被省略?
我认为这涵盖了它。感谢您的任何更正或进一步的描述。
凯尔
Apologies if this is too naive or obvious but after a fair bit of searching around, I'm not 100% sure that I understand the fortran/unix interface. My uncertainty is regarding the nature of .src, .f, then .o, and .out files that you run into when compiling fortran programs into a unix executable. It's tough to google file extensions like this. But if you could tell me if I've got this straight, I'd really appreciate it!
.src is the source file which contains the meaty fortran code
.f is the 'host-language specific include file' that tells your fortran compiler a little bit about the source code. It's sometimes interactive.
--- After you've obtained .o or .out files, can throw away the .src and .f files, yeah?
.o is the binary object file that results from compiling but not linking the fortran .f and .src files. It contains the same meat but now converted into machine-specific instructions?
.out is the linked object file(s) which is executable and remains dependent on the .o file(s) and is machine-specific. The .out file extension is not really needed and is often omitted?
I think that covers it. Thanks for any corrects or further descriptions.
Kyle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这些文件扩展名并不是一成不变的。正如你所说,它们甚至可以被省略,或者你可以自己弥补。但是,如果您使用传统的方法,生活会变得更加轻松。
我从未见过
.src
扩展名。源文件所在目录通常称为./src
;也许你已经看过这个。通常,源代码(纯文本)位于扩展名为
.f
或.f90
的文件中。第一个表示固定源形式(“旧式”),第二个表示自由源形式(“现代”)。某些编译器将大写文件扩展名(.F
和.F90
)解释为源必须首先通过预处理器运行的指示。所有这些都可以通过向编译器传递标志来显式声明/否决,而不是让编译器使用这些解释的扩展。源代码的编译生成目标代码(您提到的特定于机器的指令),包含在目标文件中,通常以
.o
作为扩展名(有时.obj
,或其他)。创建目标文件后,您确实可以丢弃源代码文件,但您不想这样做。您想要修复您最有可能犯下的任何错误,并保留它们以供将来更改程序时使用。
必须链接目标代码才能生成最终的可执行文件。如果您有多个目标文件,它们会捆绑在一起,并包含您引用的任何系统/外部库代码。在 Unix 上,如果您没有为可执行文件指定名称,则它获得的默认名称通常是
a.out
。同样,您可以通过向编译器传递参数来推翻这一点。Nothing about these file extensions is set in stone; as you said, they can even be omitted, or you can make up your own. However, it makes life far easier if you use the conventional ones.
I've never seen the
.src
extension. The directory where the source files are located is often referred to as./src
; maybe you've seen this.Usually, the source code (plain text) is in a file with extension
.f
or.f90
. The first one indicates fixed source form ("old style"), and the second one free source form ("modern"). Some compilers interpret uppercase file extensions (.F
and.F90
) as an indication that the source has to be run through the preprocessor first. Instead of letting the compiler use the extensions for these interpretations, all this can also be explicitly stated/overruled by passing flags to the compiler.Compilation of the source code produces object code (the machine-specific instructions you mention), contained in an object file, usually with
.o
as extension (sometimes.obj
, or other).After creating the object files, you could indeed throw away your source code files, but you don't want to do that. You want to fix any bugs you most likely made, and also keep them for future alterations to your program.
The object code has to be linked to produce the final executable. If you have more than one object file, they are tied together, with inclusion of any system/external library code you referred to. On Unix, if you don't specify a name for the executable, the default name it gets is usually
a.out
. Again, you can overrule this by passing an argument to the compiler.不,Fortran 代码通常位于 .f 或 .f90 文件中。更详细地说,如果 Fortran 源代码使用固定源代码形式(Fortran 77 及更早版本的标准源代码形式),则它通常具有扩展名 .f;如果使用自由源代码形式(从 Fortran 90 开始存在),则通常具有 .f90 扩展名。
No, the Fortran code is usually in .f or .f90 files. In more detail, Fortran source code usually has the extension .f if it uses the fixed source form (the standard source form of Fortran 77 and earlier versions) or .f90 it uses free source form (present from Fortran 90 on).
否。作为描述各种后缀约定的答案的附录,我建议您不要删除 Fortran 源文件(
.src
或.f描述中的
文件)。如果您想要修改程序,或者需要调查并修复在运行可执行文件 (a.out
) 时发现的错误,您将需要这些文件。No. As an addendum to the answers describing the various suffix conventions, I advise that you don't delete the Fortran source files (the
.src
or.f
files in your description). You'll need these files if you ever want to modify the program, or if you need to investigate and fix errors you notice from running the executable file (a.out
).