gfortran编译器给出分段错误



我在运行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操作系统,感觉Xcode/Anaconda/等把我的系统搞砸了。

我使用的是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,但也没用。

据我所见,代码很好,它符合要求并在我的系统上正确运行

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已经被打破了。但请始终使用隐式无

最新更新