[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 20000712: linux f77 undefined references



>To: address@hidden
>From: Edward Colon <address@hidden>
>Subject: linux f77 undefined references
>Organization: UCAR/Unidata
>Keywords: 200007121602.e6CG2hT11473

Hi Edward,

> I am using Redhat linux on my pc and have encountered a frustrating compiling 
> pr
> oblem. Netcdf and udunits libraries, include files, and executables were 
> success
> fully installed on my system. My LD_LIBRARY_PATH = 
> /usr/lib:/usr/local/lib:/home
> /ecolon/epic/netcdf/lib which includes all the libraries needed for linking. 
> The
>  code is a simple program borrowed from another user in your help list and is 
> gi
> ven as
> 
> >      program test_cdf
> >
> >      implicit none
> >
> >      include '/usr/local/include/netcdf.inc'
> >
> >      integer  ncid, status
> >
> >      print*, nf_float
> >
> >      status = NF_CREATE("test.nc", 0, ncid)
> >      status = NF_CLOSE(ncid)
> >
> >      print*, status
> >      print*, ncid
> >
> >      end
> 
> When I compile I receive the messages:
> 
> /tmp/cca251281.o: In function `MAIN__':
> /tmp/cca251281.o(.text+0x42): undefined reference to `nf_create__'
> /tmp/cca251281.o(.text+0x53): undefined reference to `nf_close__'
> 
> which indicates that he netCDF entry points
> nf_create__ and nf_close__ are not being found during the link. So I have 
> tried to link the netcdf fortran libary explicitly using the compile statement
> 
> f77 -L/home/ecolon/epic/netcdf/lib/libnetcdf.a simple.f 
> 
> but this did not help and I received the same compiler errors. I
> would greatly appreciate any assistance you can offer.

The above f77 line won't find the library because you have the library
specification BEFORE the Fortran source-file.  Switch them and either
just provide the library explicitly (without the -L which takes a
directory argument):

  f77 simple.f /home/ecolon/epic/netcdf/lib/libnetcdf.a

or use the -L option with the directory and a -l option for the
library name:

  f77 simple.f -L/home/ecolon/epic/netcdf/lib -lnetcdf

This might solve the first problem too.  You shouldn't have to add the
netCDF library directory to your LD_LIBRARY_PATH to link executables
with it.  

One way to see how to link executables is to go to the src/ directory
of the original netCDF distribution after it has been compiled with
"make all", delete a few of the executables such as fortran/nftest,
and then try "make test" to see how the test program gets rebuilt and
linked.

--Russ