Fortran 95 编译器可以编译 Fortran 77 代码吗?

Can Fortran 95 compiler compile Fortran 77 code?

目前我正在 mac 使用 gfortran 6.1 编译 fortran95 源代码。我想知道我是否可以使用相同的 运行 FORTRAN 77 源代码。如果没有,有什么建议吗?

你没有提到你在编译过程中遇到了什么错误。参见 this link。具体来说:

    -std=*std*

其中 std 可能是“f95”、“f2003”、“f2008”、“gnu”或“legacy”之一。

Default value for std is ‘gnu’. From the same page: The ‘legacy’ value is equivalent but without the warnings for obsolete extensions, and may be useful for old non-standard programs. The ‘f95’, ‘f2003’ and ‘f2008’ values specify strict conformance to the Fortran 95, Fortran 2003 and Fortran 2008 standards, respectively; errors are given for all extensions beyond the relevant language standard, and warnings are given for the Fortran 77 features that are permitted but obsolescent in later standards.

例如,如果你有一个文件old_fortran.f77要编译,你可以这样做:

   gfortran -std=legacy old_fortran.f77 -o a.out

其中 -o a.out 为您提供可执行文件 a.out。我在没有使用这个选项的情况下成功地使用了这个编译器的旧版本。不过,您可能会收到一些警告。第一次尝试:

   gfortran old_fortran.f77 -o a.out

编辑:在查看了 OP 的以下评论后,看起来可能涉及另一个问题。可能是您的安装有误(这是可能的)或您的 LD_LIBRARY_PATH 搞砸了。我认为您的路径中的链接器 (ld) 是 32 位的,而您的编译器创建的目标文件可能是 64 位的。只是一种预感。你能 post

的输出吗
  which ld

假设returns:/path/to/ld。然后获取该输出并执行

  file /path/to/ld

你能post将两个命令的输出作为注释吗?

如果我使用它就可以工作

gfortran old_fortran.f -o a.out