On 2012-08-03, Nasser M. Abbasi <
n...@12000.org> wrote:
> This question is about the location and name of the gfortran library
> libgfortran.so
>
> I am trying to make a build script that will build a fortran program
> on different linux distributions without having to change it.
>
> On linux mint, this file is located in
>
> /usr/lib/i386-linux-gnu/libgfortran.so
>
> and on linux mageia
>
> /usr/lib/libgfortran.so
>
> Both are using gfortran 4.6.3
While I have no experience with the particular distros you mention, I
suspect that the likely reason is that debian and distributions
derived from it such as Ubuntu, have recently started using something
called multiarch. See
http://wiki.debian.org/Multiarch/
for more details and rationale.
> I had a script where I was explicitly adding libgfortran to
> the gfortran command and so it failed on one system but
> worked on the other.
>
> Then I found that I actually do not need to have this library
> explicitly added. If I remove it, the gfortran will still link the
> program fine. i.e., I was doing this before:
>
> gfortran foo.f90 -L /usr/lib -lgfortran (among many other libraries)
>
> but it still works when I do
>
> gfortran foo.f90 -L/usr/lib (removed -lgfortran but kept all other libraries)
>
> So my questions
>
> 1) How does gfortran find libgfortran when I do NOT include
> the path using -L as above?
The default search path is hardcoded into the gfortran binary when
it's built. Depending on options set during the build, that default
may be different on different systems (e.g. /usr/lib
vs. /usr/lib/{arch-triplet})
> 2) Is there ever a need to explicitly add libgfortran.so to the
> build command? If not, then I do not need to worry about
> libgfortran being in different places, right?
Only if you're not using gfortran to do the final linking. This
happens e.g. if you have a C or C++ main program and you link to some
.o files which have been created with gfortran and need
libgfortran. Even so you shouldn't need to worry about the path, since
gcc and g++ also add the gcc private library path to their search
path, just like gfortran (which is how g++ finds libstdc++, the C++
library, for instance).
--
JB