3
votes

Since upgrading to Yosemite I cannot compile with gfortran. Initially I was getting "segmentation fault 11", then I:

  1. Updated to gcc v.5.0 from http://hpc.sourceforge.net/
  2. Re-installed Xcode command line utilities v.6.1.1

After doing the above, I am able to compile very simple fortran programs but the more complex code that I run gives me the following error:

 gfortran: error: libgfortran.spec: No such file or directory

But in fact, the libgfortran.spec file is located in /usr/local/lib

 ls /usr/local/lib | grep gfortran

 libgfortran.3.dylib
 libgfortran.a
 libgfortran.dylib
 libgfortran.la
 libgfortran.spec

All of the gcc binaries are located in /usr/local/bin

 which gfortran

 /usr/local/bin/gfortran

And my path seems to be OK

 echo $PATH
 /usr/local/lib:/usr/local/bin:/usr/local:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/lib:/usr/texbin:/Users/MattCooper/bin:/Applications/MRT/bin

I also tried re-installing gcc with homebrew:

 brew install gcc
 Error: gcc-4.9.2 already installed
 To install this version, first 'brew unlink gcc'

However, I get v. 5.0 when I ask 'gcc --version':

 gcc --version
 gcc (GCC) 5.0.0 20141005 (experimental)

When I try to unlink or upgrade gcc with homebrew I get a permission denied error:

 brew unlink gcc
 Unlinking /usr/local/Cellar/gcc/4.9.2... Error: Permission denied - /usr/local/bin/c++-4.9

similarly

 brew upgrade gcc
 Permission denied - /usr/local/bin/c++-4.9

Finally

 which gcc
 /usr/local/bin/gcc

Please help. Many thanks ahead of time. Please let me know what I've forgotten to include.

2

2 Answers

4
votes

I ended up solving the problem via homebrew. I can't pinpoint the exact source of the problem but it was related to the fact that I installed gcc v4.9 from http://hpc.sourceforge.net/, then somewhere along the way I re-installed and/or updated gcc with homebrew. Then, after upgrading to Yosemite, I installed gcc v5 from http://hpc.sourceforge.net/. Somewhere within that process, the binaries within /usr/local/bin and usr/local/lib were not linked properly.

The main clue was the Permission Denied error when trying to run 'brew upgrade gcc'. I found a solution here: Brew doctor says: "Warning: /usr/local/include isn't writable."

To fix, I used:

 brew doctor

which returned a bunch of directories that were not writeable, for example usr/local/lib, thus brew was unable to ugrade gcc to the v5.0 and link everything.

I went through and issued:

 sudo chown -R $USER /usr/local

and did this for all of the other non-writeable directories returned by 'brew doctor'. Then, I was able to use brew to ugrade gcc:

 brew upgrade gcc

During the ugrade, homebrew returned an error that stated it could not finish the upgrade because there was already an existing gfortran file located in:

 /usr/local/bin/gfortran

To fix, homebrew suggested I run:

 brew -link gcc

at which point everything worked. Interesting (to me, because I don't fully understand all of this) when I ask brew to clean things up, I get:

 brew cleanup
 Warning: Skipping (old) /usr/local/Cellar/gcc/4.9.2 due to it being linked

There's some similar information located here: How to link to a new gcc version with brew?

Similar to that user, when I look in my cellar, I find two versions of gcc, but I'm not sure if I need both

 ls /usr/local/Cellar/gcc
 4.9.2 4.9.2_1
1
votes

I had a similar issue with similar solution. It could not find this file:

gfortran: error: libgfortran.spec: No such file or directory

So my problem was that I had installed gcc through hpc.sourceforge.net and through homebrew. I had to uninstall the homebrew version

brew uninstall gcc

Then I had to reinstall the gcc from hpc.sourceforge.net

sudo tar -xvf gcc-4.9-bin.tar.gz -C /

This worked for me when I wanted to revert to gcc 4.9 from hpc.sourceforge.net, using Yosemite.