Hi,
I am trying to compile Fortran 90 programs and have a Makefile for that. I want to link to netCDF libraries (openSUSE 15 provided ones).
I tried to adapt an already available Makefile. These are the relevant lines in my Makefile:
FC = gfortran
ROOTDIR = /media/work/codes/fortran
SRCDIR = $(ROOTDIR)/src
BLDDIR = $(ROOTDIR)
EXEDIR = $(ROOTDIR)
FPROGS = ascii2nc
NC_C_DIR = /usr/lib/hpc/gnu7/openmpi3/netcdf/4.6.1
NC_FORT_DIR = /usr/lib/hpc/gnu7/openmpi3/netcdf-fortran/4.4.4
NC_C_LIB = $(NC_C_DIR)/lib64
NC_FORT_LIB = $(NC_FORT_DIR)/lib64
NCLIB = -L$(NC_FORT_LIB) -L$(NC_C_LIB) -lnetcdff -lnetcdf
NC_FORT_INC = $(NC_FORT_DIR)/include # netCDF's netcdf.mod file
NCINC = $(NC_FORT_INC)
INCLUDES = -I$(NCINC) -I$(FFTINC)
FOPTS = -Wall -O2 #-fno-range-check
FFLAGS = $(FOPTS) $(INCLUDES)
LFLAGS = $(NCLIB) $(FFTLIB)
VPATH = $(shell cat $(BLDDIR)/Filepath) # 'Filepath' is same as $(SRCDIR)
all: $(FPROGS)
DEPS = depends # Contains list of dependencies
# This writes all dependencies on 'depends'
$(BLDDIR)/$(DEPS): $(BLDDIR)/Srcfiles $(BLDDIR)/Filepath
$(BLDDIR)/mkDepends Filepath Srcfiles > $@
# This writes all F90 files on 'Srcfiles'
$(BLDDIR)/Srcfiles: $(BLDDIR)/Filepath
$(BLDDIR)/mkSrcfiles > $@
an_objs = ascii2nc.o shr_vars.o nc_mod.o nl_read.o shr_kind_mod.o \
grid_gen.o endrun.o
ascii2nc: $(an_objs)
$(FC) -o $@ $(an_objs) $(FFLAGS) $(LFLAGS)
.SUFFIXES:
.SUFFIXES: .F90 .o
.F90.o:
$(FC) -c $(FFLAGS) $(LFLAGS) $<
include $(BLDDIR)/$(DEPS)
The error i am getting is:
gfortran -o ascii2nc ascii2nc.o shr_vars.o nc_mod.o nl_read.o shr_kind_mod.o grid_gen.o endrun.o -Wall -O2 -I/usr/lib/hpc/gnu7/openmpi3/netcdf-fortran/4.4.4/include -I -L/usr/lib/hpc/gnu7/openmpi3/netcdf-fortran/4.4.4/lib64 -L/usr/lib/hpc/gnu7/openmpi3/netcdf/4.6.1/lib64 -lnetcdff -lnetcdf -lfftw3
/usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: cannot find -lnetcdff
collect2: error: ld returned 1 exit status
make: *** [Makefile:128: ascii2nc] Error 1
Can someone help?
Thanks.
I don’t know anything about NETCDF, and I haven’t used FORTRAN for ages. However, this line in your “Makefile” is related:
NCLIB = -L$(NC_FORT_LIB) -L$(NC_C_LIB) -lnetcdff -lnetcdf
You might try removing the “-lnetcdff” from that line (but leave the “-lnetcdf” there).
That should avoid the particular error message you are seeing. It might cause other error messages, but it is worth trying.
Hi,
Thanks for the reply.
-lnetcdff links to the fortran libraries of netCDF, -lnetcdf links to the C linrary functions of netCDF. I read in some post that the correct sequence is -lnetcdff -lnetcdf
As you said, i tried removing -lnetcdff, but the errors i got were related to the fortran library functions in netCDF (undefined reference type errors).
I am able to compile netCDF by myself and use it, but am unable to use the netCDF provided by openSUSE although all required linraries and headers are available fro openSUSE netCDF package.
Do you see any issues with my Makefile?
If they were available you would not see this error.
fro openSUSE netCDF package.
Libraries required for compilation are part of *-devel packages, not run-time packages. Does netcdf-devel exist?
They seem to be there. I thought that there is a problem with my Makefile.
netcdf-devel is there in the repos but i didnt install it as i need netcdf-fortran whose packages are not provided by netcdf-devel. Hence i installed:
libnetcdf-fortran_4_4_4-gnu-openmpi3-hpc
libnetcdf-gnu-openmpi3-hpc
libnetcdf13
libnetcdf_4_6_1-gnu-openmpi3-hpc
netcdf
netcdf-fortran-gnu-openmpi3-hpc-devel
netcdf-fortran_4_4_4-gnu-openmpi3-hpc-devel
netcdf-fortran_4_4_4-gnu-openmpi3-hpc-devel-static
netcdf-gnu-openmpi3-hpc-devel
netcdf_4_6_1-gnu-openmpi3-hpc-devel
netcdf_4_6_1-gnu-openmpi3-hpc-devel-static
tsu2
July 14, 2018, 2:39am
6
Sounds like you still need to install the development files for your specific fortran library.
the following link lists all the netcdf-fortran packages, both the main packages and packages with development files.
Looks like the development files don’t file the normal convention where the package name ends in “-devel”
The “-devel” is embedded in the middle of the name, so is harder to find.
But you should start with the specific package name of what you have installed which has the version number, the corresponding development files package should be close by on the page
https://software.opensuse.org/search?utf8=✓&q=netcdf-fortran
I would also imagine if you did a zypper search, the development files package should be listed immediately after your installed package
zypper se netcdf-fortran
TSU