mxcl/homebrew — Issue #8539: Library libgfortran not found after installing gfortran
Author: rwest
Created: 2011-11-10 21:17:00+00:00
State: open

After installing gfortran, I have the following libraries:

```
/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/libgfortran.a
/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/libgfortranbegin.a
/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/libgfortranbegin.la
/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortran.a
/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortranbegin.a
/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortranbegin.la
```

And I have the link `/usr/local/lib/gcc -> ../Cellar/gfortran/4.2.4-5666.3/lib/gcc`

so that they can be found at

```
/usr/local/lib/gcc/i686-apple-darwin11/4.2.1/libgfortran.a
/usr/local/lib/gcc/i686-apple-darwin11/4.2.1/libgfortranbegin.a
/usr/local/lib/gcc/i686-apple-darwin11/4.2.1/libgfortranbegin.la
/usr/local/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortran.a
/usr/local/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortranbegin.a
/usr/local/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/libgfortranbegin.la
```

However, when I try to build things with, for example, `/usr/bin/llvm-gcc -bundle -undefined dynamic_lookup ... -lgfortran ...` I get:

ld: library not found for -lgfortran
collect2: ld returned 1 exit status
error: command '/usr/bin/llvm-gcc' failed with exit status 1

It is failing to find any libgfortan.a.

Various workarounds are described by other people who have had this problem, for example:

https://github.com/zk00006/OpenTLD/wiki/InstallingOctave-Mac

> Currently Mac homebrew won't install libgfortran to your default library path (even with brew link). So we also must create links to libgfortran in /usr/local/lib.

http://eris.liralab.it/wiki/Homebrew

> following links I created after installing gfortran by "brew install gfortran".
ln -s /usr/local/Cellar/gfortran/4.2.4-5664/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgfortran.a /usr/local/lib/libgfortran.a
ln -s /usr/local/Cellar/gfortran/4.2.4-5664/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgfortranbegin.a /usr/local/lib/libgfortranbegin.a
ln -s /usr/local/Cellar/gfortran/4.2.4-5664/lib/gcc/i686-apple-darwin10/4.2.1/x86_64/libgfortranbegin.la /usr/local/lib/libgfortranbegin.la

http://obspy.org/wiki/InstallingDependenciesMac

>obspy.taup is linked against libgfortran.a and for some reason it is not found. You will have to search for libgfortran.a on your system and add the corresponding path to the LIBRARY_PATH variable to be able to link anything against the fortran library using another compiler. I am not sure how this can be avoided (See ticket #262 for more information). Change the path according to your system (it will be something similiar if you installed gfortran using brew):
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/Cellar/gfortran/4.2.4-5666.3/lib/gcc/i686-apple-darwin11/4.2.1/x86_64/

**What is the best way to solve this?**