2

I tried upgrading to El-Capitan and Xcode 7.0 and now gfortran doesn't work. Everytime I run gfortran, I get errors which google search doesn't seem to resolve so I'm asking stack overflow:

I'm trying to compile a minimal example program:

program hello
print *, "Hello World"
end program hello

When I run gfortran test.f

gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
ld: library not found for -lgcc_s.10.4
collect2: error: ld returned 1 exit status

I'm not worried about the warning but the error of the ld is what's really bothering me. There's libgcc_s.10.4.tbd in the /usr/lib folder but it seems not be used by gfortran.

Can anyone help me resolve this as I would like to use gfortran for compiling some libraries?

MORE info: running gfortran -v outputs

gfortran: warning: couldn’t understand kern.osversion ‘15.0.0
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/x86_64-apple-darwin12.2.0/4.8.0/lto-wrapper
Target: x86_64-apple-darwin12.2.0
Configured with: ../gcc-4.8-20120930/configure --enable languages=c++,fortran
Thread model: posix
gcc version 4.8.0 20120930 (experimental) (GCC)
Ross
  • 2,130
  • 14
  • 25
jdwhitfield
  • 135
  • 1
  • 6
  • where did you install gfortran from (e.g. macports, homebrew, manually, etc)? – casey Oct 06 '15 at 19:16
  • I think its from the command line tools installed via "xcode-select --install" I don't have homebrew or macports (that I know of). – jdwhitfield Oct 06 '15 at 20:10
  • in that case, what does `gfortran -v` print. AFAIK xcode does not provide a Fortran compiler and the gcc they ship is just a front-end for llvm/clang. – casey Oct 06 '15 at 20:15
  • I added the output to the question because it looked ridiculous in the comment field – jdwhitfield Oct 06 '15 at 20:22
  • https://stackoverflow.com/questions/26919450/can-not-install-gfortran-via-homebrew# – Ferroao Oct 31 '17 at 18:08

1 Answers1

3

The version of gfortran you have (4.8 installed into /usr/local) is not a version of GCC that apple would have distributed with Xcode (afaik they never made it to a version of GCC that new before switching to llvm, which has no Fortran front-end. The version of gcc distributed with Xcode 7 on el capitan identifies itself as:

Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/usr/include/c++/4.2.1
Apple LLVM version 7.0.0 (clang-700.0.72)
Target: x86_64-apple-darwin15.0.0
Thread model: posix

Your version came from somewhere else and is old enough to not know the x86_64-apple-darwin15.0.0 target. You'll need to update that compiler to get a working gfortran. Both macports and homebrew provide easy installations of various versions of gcc/gfortran on OS X el capitan, and I'd recommend using one of those to install gcc. Alternatively you can track down whatever you used to install gcc 4.8 before and see if they provide an update for el capitan.

casey
  • 6,855
  • 1
  • 24
  • 37
  • @jdwhitfield the xcode version of gcc is in `/usr/bin`. You can invoke it directly as `/usr/bin/gcc` or change your `PATH` so it is found first. You can query its version as `/usr/bin/gcc -v`. It will use lvm/clang/clang++ to compile C,C++,ObjC but the Xcode version does not have a Fortran front end and no production quality Fortran front-end exists for llvm. – casey Oct 07 '15 at 14:13