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

Chr*_*vin 2 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
Run Code Online (Sandbox Code Playgroud)

以下简单的测试程序显示了该问题。它可以在没有 -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
Run Code Online (Sandbox Code Playgroud)

这有效: gfortran main.f90

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

我正在使用 gfortran 8.2 的 MacPorts 版本

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.
Run Code Online (Sandbox Code Playgroud)

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

Vla*_*r F 6

FSEEK流访问不需要的扩展内部子例程。您可以从任何您想要的位置阅读

read(10, pos=42) i
Run Code Online (Sandbox Code Playgroud)

您还可以通过语句获取当前位置inquire

inquire(unit=10, pos=current_pos)
Run Code Online (Sandbox Code Playgroud)