1

I use a model is written Fortran90 under Ubuntu 14.04. The gfortran 95 compiler (gfortran 4:4.8.2-1ubuntu6) and the gcc 4:4.8.2-1ubuntu6 is installed by Ubuntu Software Center. The installed gcc has an 4.9 empty folder in usr/lib/gcc/x86_64-linux/gnu as well. The required netCDF libraries (netCDF C and Fortran netCDF) are installed as suggested in: http://www.unidata.ucar.edu/software/netcdf/docs/. The netcdf is built as shared library.

The compiler options and LDFLAGS is set in the compiler_options.inc file by the following way:

ifeq ($(COMPILER), gfortran)
FPP= -x f95-cpp-input 
ifdef TESTING 
OPTS=-g -O0 -W -Wall -pedantic-errors -fbounds-check -fbacktrace \
-ffpe-trap=invalid,zero,overflow -frange-check #-Werror 
else
OPTS=-O3 -pg -g
endif
endif

INCDF=-I$(NCPATH)/include 
LNCDF=-L$(NCPATH)/lib -lnetcdff -lnetcdf 
LDFLAGS=$(INCDF) $(LNCDF) 

When I compile the model I get the following messages:

/home/Beata/kid_a_setup/src/test_cases_2d.f90:1446: undefined reference to  `_gfortran_runtime_error_at' 
/home/Beata/kid_a_setup/src/test_cases_2d.f90:1446: undefined reference to `_gfortran_runtime_error_at' 
/home/Beata/kid_a_setup/src/test_cases_2d.f90:1446: undefined reference to `_gfortran_runtime_error_at' 
/home/Beata/kid_a_setup/src/test_cases_2d.f90:1449: undefined reference to `_gfortran_runtime_error_at' 
../obj/test_cases_2d.o:/home/Beata/kid_a_setup/src/test_cases_2d.f90:1449: more   undefined references to `_gfortran_runtime_error_at' follow 
../obj/test_cases_2d.o: In function `__test_cases_2d_MOD_set_gate_thermo_profile':

It seems that gcc may not have found fortran libraries.

Could someone explain me what causes the error and how I can fix it?

  • Does your makefile specify more libraries elsewhere? otherwise it seems like you're not linking the gfortran library itself (-lgfortran). – steeldriver Feb 5 '15 at 12:39
  • Thank you for your response. Only compiler_option.inc file contains definition about LDFLAGS which contains netcdf libraries. I do not know exactly how I should fix the linking to gfortran library. Does the following export command fix the matter? export LDFLAGS=-L/usr/lib/gcc/x86_64-linux-gnu/4.8/ – Beata Feb 5 '15 at 14:12
  • The compiler_options.inc file mixes up compile-time options (include paths) and link-time options (library paths and libraries), which confuses matters imho. However the simplest thing to try would be to add -lgfortran to the LDFLAGS. You should consider including the relevant portion of the makefile as well, i.e. the rule(s) for your executable target(s). – steeldriver Feb 5 '15 at 14:19
  • I add the -lgfortran to LDFLAGS by the following way: INCDF=-I$(NCPATH)/include LNCDF=-L$(NCPATH)/lib -lnetcdff -lnetcdf LFOR=-L/usr/lib/gcc/x86_64-linux-gnu/4.8/libgfortran.a LDFLAGS=$(LFOR) $(INCDF) $(LNCDF) but I got the same error messages. I tried again without /ligfortran.a but it neither solved the matter. – Beata Feb 5 '15 at 15:00
  • You're over-complicating things, I think. There should be no need to specify a path to the library, just literally add -lgfortran i.e. LDFLAGS=$(INCDF) $(LNCDF) -lgfortran – steeldriver Feb 5 '15 at 15:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.