0

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 Dec 07 '20 at 12:18
  • exit -> exact in previous comment ... – Ian Bush Dec 07 '20 at 13:31
  • See alsohttps://stackoverflow.com/questions/65164717/error-when-compile-umfpack-after-the-update-of-mac?noredirect=1#comment115220789_65164717 and note the conclusion: recompile **everything** – Vladimir F Героям слава Dec 07 '20 at 14:03
  • 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 Dec 07 '20 at 16:14
  • @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 Героям слава Dec 07 '20 at 16:50
  • @VladimirF Alright, thanks! – Quercus Robur Dec 07 '20 at 18:44

1 Answers1

1

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
raspy
  • 3,995
  • 1
  • 14
  • 18
  • Thanks for your answer! While it answers my direct question, it still leaves me confused. On the computers where the compilation does work with the flag -lgfortran, the command readlink -f $(gfortran --print-file libgfortran.so) returns /usr/lib64/libgfortran.so.3.0.0. Should it not then be equivalent to use "-lgfortran" or tu use "-L/usr/lib64/libgfortran.so.3.0.0"? The former works, but the latter does not. – Quercus Robur Dec 07 '20 at 15:01
  • @QuercusRobur Did you see the comments under your question? – Vladimir F Героям слава Dec 07 '20 at 16:11
  • @QuercusRobur, No. `-Lyyyy` is used to add the directory `yyyy` to the search path. `-lxxxx` tells the compiler to link in the library `libxxxx.a` (static linking) or `libxxxx.so.#.#` (shared linking). – evets Dec 07 '20 at 16:20
  • @VladimirF Thank you for your comment! Yes, I managed to resolve the issue by recompiling everything. – Quercus Robur Dec 07 '20 at 16:20
  • @evets Thank you for clarifying this! I am new to (GNU) make. – Quercus Robur Dec 07 '20 at 16:22