fortran - gfortran -std=f2008 如果调用 fseek 存在则编译标志错误

标签 fortran gfortran

我正在尝试使用 gfortran 强制执行 Fortran 2008 一致性检查。当我使用 -std=f2008 编译时,出现以下错误:

Undefined symbols for architecture x86_64:
  "_fseek_", referenced from:
      _MAIN__ in ccJtOcKa.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status

以下简单的测试程序显示了该问题。它可以在没有 -std=f2008 的情况下正常编译和运行,但在设置此标志时不会编译。

program main
  implicit none
  integer :: i
  open(unit=10, file='test.bin', access='stream')
  write(10) 100

  !fseek works, but will not compile with -std=f2008
  call fseek(10, -4, 1)
  read(10) i
  print *, i
end program

这有效: gfortran main.f90

这给出了错误: gfortran -std=f2008 main.f90

我使用的是 MacPorts 版本的 gfortran 8.2

GNU Fortran (MacPorts gcc8 8.2.0_3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

fseek 不是 fortran 2008 标准的一部分吗?如果是这样,是否有其他方法可以做到这一点?

最佳答案

FSEEK 一个扩展内部子例程,对于流访问来说是不必要的。您可以从任何您想要的位置阅读

read(10, pos=42) i

您还可以使用inquire语句获取当前位置。

inquire(unit=10, pos=current_pos)

关于fortran - gfortran -std=f2008 如果调用 fseek 存在则编译标志错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58877345/

相关文章:

performance - 有什么办法可以避免这些嵌套循环吗?

linux - 编辑和编译 MPIs FORTRAN 代码

module - FORTRAN 95 : is it possible to share a module without sharing the source code?

c - 我需要帮助将 Fortran 代码转换为 C 代码

fortran - Fortran 结果中的 FFTW 仅包含零

Fortran 数组无法在函数 : not a DUMMY variable 中返回

fortran - 具有重载赋值的嵌套派生类型

compiler-errors - Fortran - 无法从主机范围单元导入 `c_char`

debugging - 无法运行 fortran 调试器。 Visual Studio Code

fortran - 编译 Fortran 是否需要接口(interface) block ?