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 I did
gfortran -o hello3 hello3.f -g3 -fcheck=all -Wall -fbacktrace
And it gave me no warning nor error. However,
./hello3
failed with
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 I somehow feel like my gfortran compiler doesn't work properly. I'm not familiar with Mac OS and feel like Xcode/Anaconda/etc messed up my system.
I'm using 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.