I was having trouble running fortran code, so I tried an example code in here: 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 path is /usr/local/bin/gfortran Currently my gfortran is from 'brew install gcc'. I also tried manual download from https://github.com/fxcoudert/gfortran-for-macOS/releases, but it didn't worked either.