0
votes

I am trying to compile a build for c++ and Fortran using GNU make. On some machines the build works, on others I get the error undefined reference to '_gfortran_stop_numeric_f08'. I reckon there is some issue with the fortran library, and I am trying to figure this out.

On the machines where the compilation works, the gfortran version is "GNU Fortran (SUSE Linux) 4.8.5". In /usr/lib64/ I have the following library files:

libgfbgraph-0.2.so.0 libgfortran.so.3 libgfortran.so.4 libgfbgraph-0.2.so.0.0.0 libgfortran.so.3.0.0 libgfortran.so.4.0.0

On these machines, compiling with the LDFlag -lgfortran works fine. However, compiling with either -L/usr/lib64/libgfortran.so.4 or -L/usr/lib64/libgfortran.so.3 gives a long list of errors, of the form

/usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/bin/ld: io.f90:(.text+0x888d): undefined reference to `_gfortran_st_write'

It seems then that using the flag -lgfortran I am not pointing to either -L/usr/lib64/libgfortran.so.4 or -L/usr/lib64/libgfortran.so.3. Howe can I figure out the library which is actually pointed to?

On the other machines, the compilation does not work even with the flag -lgfortran. This is where I get the error undefined reference to '_gfortran_stop_numeric_f08'. On these machines, the gfortran version is GNU Fortran (SUSE Linux) 7.5.0". In /usr/lib64/ I have the following library files:

libgfortran.so.4 libgfortran.so.4.0.0

Any ideas about how to resolve this?

1
Can you show us the exit link lines you are using, please? A bit of googling shows gfortran_stop_numeric_f08 disappeared around gfortran version 7.2 so something in the code has been compiled by an earlier version, and hence the undefined reference with the slightly old 7.5.0, but the ancient 4.8.5 seems to find it.Ian Bush
exit -> exact in previous comment ...Ian Bush
See alsohttps://stackguides.com/questions/65164717/error-when-compile-umfpack-after-the-update-of-mac?noredirect=1#comment115220789_65164717 and note the conclusion: recompile everythingVladimir F
Thanks for your comments! The problem appears to have been resolved by recompiling everything. Of course, I still don't understand why it is not equivalent to use "-lgfortran" or to use "-L/usr/lib64/libgfortran.so.3.0.0", when "/usr/lib64/libgfortran.so.3.0.0" is the output of "readlink -f $(gfortran --print-file libgfortran.so)".Quercus Robur
@QuercusRobur Because you were mixing code from older and more recent Gfortran. libgfortran.so.3 is the old version, you cannot just link it in addition to the libfortran that comes with the more recent version of gfortran.Vladimir F

1 Answers

1
votes

The library linked when providing -lgfortran will always be libgfortran.so. Most commonly this is a symbolic link to an actual file, which will be later referenced by compiled binary.

Now, since this is a compiler-provided library, its location can be determined by calling compiler, e.g.:

# Custom compiler
$ gfortran --version
GNU Fortran (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.

$ gfortran --print-file libgfortran.so
/proj/subcm/tools/Linux-x86_64/Santiago/lib/gcc/x86_64-pc-linux-gnu/10.2.0/../../../../lib64/libgfortran.so

$ readlink -f $(gfortran --print-file libgfortran.so)
/proj/subcm/tools/Linux-x86_64/Santiago/lib64/libgfortran.so.5.0.0


# Stock distribution compiler
$ /usr/bin/gfortran --version
GNU Fortran (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Copyright (C) 2015 Free Software Foundation, Inc.

$ /usr/bin/gfortran --print-file libgfortran.so
/usr/lib/gcc/x86_64-redhat-linux/4.8.5/libgfortran.so

$ readlink -f $(/usr/bin/gfortran --print-file libgfortran.so)
/usr/lib64/libgfortran.so.3.0.0