如何使用 *.h 文件编译这个旧版 FORTRAN 77 代码?

发布于 2024-11-04 16:41:20 字数 1107 浏览 2 评论 0原文

我有一组组成 FORTRAN 代码的 .F 和 .H 文件。我在编译 .H 文件时遇到了麻烦。 .H 文件包含一堆公共块。其中一个.H文件的例子是:

*AC HEAD      
c                                                                       HEAD 1
      common/blah/ x(25), y, z(25), p(25,mnv),                          HEAD 2
     1                t(25,mx), d(25,mnv)                               HEAD 3
c                                                                       HEAD 4
ETC...

当我在google上搜索答案时,据说.h文件是c/c++文件,但它们看起来不像是用c/c++编写的。 gfortran似乎也认为它们是C文件。

当我尝试编译:

gfortran-4.5 -fdefault-real-8 -fbacktrace -fno-align-commons HEAD.h

时,出现错误:

cc1: warning: command line option "-fdefault-real-8" is valid for Fortran but not for C
cc1: warning: command line option "-fbacktrace" is valid for Fortran but not for C
cc1: warning: command line option "-fno-align-commons" is valid for Fortran but not for C
HEAD.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘HEAD’

我尝试注释掉第一行 '*AC HEAD',但随后错误是关于在 * 之前查找属性。我是否需要在最后一列中使用 HEAD # 值进行注释,我是否需要使用 C++ 编译器构建 .H 文件还是什么?

I have a collection of .F and .H files that makeup a FORTRAN code. I'm running into trouble tyring to compile the .H files. The .H files contain a bunch of common blocks. An example of one of the .H files is:

*AC HEAD      
c                                                                       HEAD 1
      common/blah/ x(25), y, z(25), p(25,mnv),                          HEAD 2
     1                t(25,mx), d(25,mnv)                               HEAD 3
c                                                                       HEAD 4
ETC...

When I search for an answer on google, it is said that .h files are c/c++ files, but they don't look like they are written in c/c++. gfortran seems to also think they are C files.

When I try to compile:

gfortran-4.5 -fdefault-real-8 -fbacktrace -fno-align-commons HEAD.h

I get the errors:

cc1: warning: command line option "-fdefault-real-8" is valid for Fortran but not for C
cc1: warning: command line option "-fbacktrace" is valid for Fortran but not for C
cc1: warning: command line option "-fno-align-commons" is valid for Fortran but not for C
HEAD.h:1:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘HEAD’

I tried to comment out the first line '*AC HEAD', but then the error was about looking for an attribute before the *. Do I need something in the last column with the HEAD # values to commment that out, do I need to build the .H files with a C++ compiler or what?

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

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

发布评论

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

评论(1

浅浅 2024-11-11 16:41:20

你不编译那些。如果您 grep 其他 fortran 文件,您会看到它们是使用 include HEAD.h 或 '#include "head.h"' 之类的内容包含的(第二个是我的猜测;我我猜测您正在 fortran 文件上运行 C 预处理器)。在编译过程中,无论 include 语句在哪里,这些 include 语句基本上都会在该 .h 文件的副本中读取。所以它是一段使用过的代码,但从未单独编译过。

Fortran 中包含头文件不再是最佳实践,而且更是如此,因为它们用于通过代码广泛分发公共块。因此,不要使用这种方法编写任何新代码。但这就是这个特定的旧代码正在做的事情。

You don't compile those. If you grep the other fortran files, you'll see that they're included using either something like include HEAD.h or '#include "head.h"' (that second is my guess; I'm guessing you're running the C preprocessor on the fortran files). Those include statements basically read in a copy of that .h file wherever the include statement is during the compilation process. So it's a piece of code that's used, but never compiled on its own.

This inclusion of header files in Fortran is not best practice any longer, and all the more so because they're used to widely distribute common blocks through the code. So don't write any new code using this approach. But that's what this particular old code is doing.

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