gfortran编译器出现分段错误

问题描述 投票:0回答:1

我在运行fortran代码时遇到麻烦,因此我在这里尝试了一个示例代码:https://gcc.gnu.org/onlinedocs/gcc-8.4.0/gfortran/ICHAR.html

program read_val
  integer value
  character(len=10) string, string2
  string = '154'

  ! Convert a string to a numeric value
  read (string,'(I10)') value
  print *, value

  ! Convert a value to a formatted string
  write (string2,'(I10)') value
  print *, string2
end program read_val

我做了

gfortran -o hello3 hello3.f -g3 -fcheck = all -Wall -fbacktrace

而且它没有给我警告也没有错误。但是,

./ hello3

失败

Program received signal SIGSEGV: Segmentation fault - invalid memory reference.

Backtrace for this error:
#0  0x103eab35c
#1  0x103eaa6f3
#2  0x7fff7376cb5c
#3  0x103fef340
#4  0x103fefd2d
#5  0x103fed78f
#6  0x103ea5cca
#7  0x103ea5e96
Segmentation fault: 11

我以某种方式感觉到我的gfortran编译器无法正常工作。我不熟悉Mac OS,感觉像Xcode / Anaconda / etc弄乱了我的系统。

我正在使用GNU Fortran(Homebrew GCC 9.3.0_1)9.3.0,MacOS Mojave 10.14.6。

gfortran路径为/ usr / local / bin / gfortran目前,我的gfortran来自“ brew install gcc”。我也尝试过从https://github.com/fxcoudert/gfortran-for-macOS/releases进行手动下载,但是也没有用。

macos fortran gfortran
1个回答
0
投票

据我所见,代码是正确的,并且在我的系统上正确地执行并调整了代码

ian@eris:~/work/stack$ cat busted.f90 
program read_val
  integer value
  character(len=10) string, string2
  string = '154'

  ! Convert a string to a numeric value
  read (string,'(I10)') value
  print *, value

  ! Convert a value to a formatted string
  write (string2,'(I10)') value
  print *, string2
end program read_val
ian@eris:~/work/stack$ gfortran -std=f2008 -Wall -Wextra -fcheck=all -g busted.f90 
ian@eris:~/work/stack$ ./a.out
         154
        154

据我所知,您对gfortran的灌输是无效的。但是请始终使用隐式None

© www.soinside.com 2019 - 2024. All rights reserved.