Find the answer to your Linux question:
Results 1 to 2 of 2
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2008
    Location
    Bangalore, India
    Posts
    14

    openSUSE 15: Unable to link using Makefile


    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:

    Note: I had to use AT in place of 'at sign' as i am not allowed to use 'at sign' here.

    Code:
    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 > $AT
    
    # This writes all F90 files on 'Srcfiles'
    $(BLDDIR)/Srcfiles: $(BLDDIR)/Filepath
        $(BLDDIR)/mkSrcfiles > $AT
    
    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 $AT $(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.

  2. #2
    Quote Originally Posted by samrat_rao View Post
    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:

    Note: I had to use AT in place of 'at sign' as i am not allowed to use 'at sign' here.

    Code:
    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 > $AT
    
    # This writes all F90 files on 'Srcfiles'
    $(BLDDIR)/Srcfiles: $(BLDDIR)/Filepath
        $(BLDDIR)/mkSrcfiles > $AT
    
    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 $AT $(an_objs) $(FFLAGS) $(LFLAGS)
    
    .SUFFIXES:
    .SUFFIXES: .F90 .o
    
    .F90.o:
        $(FC) -c $(FFLAGS) $(LFLAGS) $<
    
    include $(BLDDIR)/$(DEPS)
    The error i am getting is:



    Can someone help?

    Thanks.
    so the part where it says 'cannot find -lnetcdff" is too hard to read? either its missing or your not paying attention. lnetcdf is specified so why are you putting that library in twice? is there anyone there that knows how to code that can help you?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •