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

[netCDF #OYI-144949]: Problem when use netcdf


From the output you sent, the "make check" worked fine, and also
compiled and ran the Fortran90 examples OK.

But after running "make check", you also have to run "make install" to
install the libraries and include files in directories where the
compilers like ifort will be able to find them.  "make install" will
copy the necessary library and include files to subdirectories of
/usr/local.  You may have to run "make install" with superuser
permissions, either as root or using the "sudo" command.

After "make install" has run successfully, you can compile and link a
Fortran program.

> It shows in terminal like this :
> address@hidden:~$ ifort '/home/yue/try.f90' -lnetcdf
> /tmp/ifortKEbUgd.o: In function `MAIN__':
> /home/yue/try.f90:(.text+0x48): undefined reference to 
> `netcdf_mp_nf90_inq_libvers_'

You need to give the ifort compiler the necessary flags for where to
find the netcdf.mod file and where to find the static library
libnetcdf.a.  These are what "nc-config --fflags" and "nc-config --flibs" 

> --fflags -> -g -I/usr/local/include
> --flibs -> -L/usr/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lz -lm 
> -L/usr/lib/i386-linux-gnu -lcurl -Wl,-Bsymbolic-functions

So you can compile try.f90 to produce try.o like this:

  ifort -g -I/usr/local/include -c try.f90

Then you can link try.o with the netCDF library like this to produce the 
executable program named try:

  ifort try.o -o try -L/usr/local/lib -lnetcdf -lhdf5_hl -lhdf5 -lz -lm 
-L/usr/lib/i386-linux-gnu -lcurl -Wl,-Bsymbolic-functions

Or, you can use nc-config output on the ifort command line instead, to
specify the ifort arguments to compile and then link like this:

  ifort `nc-config --fflags` -c try.f90
  ifort try.o -o try `nc-config --flibs`

Or you can do both the compile and link steps in one ifort command, like this:

  ifort `nc-config --fflags` try.f90 -o try `nc-config --flibs`

> I have been working on it for weeks , and I can't solve it .

I hope the above helps.

You are using netCDF 4.1.1, which produces static libraries by
default.  If you decide to upgrade to netCDF 4.1.3, it
produces shared libraries by default, but also separates the C and
Fortran libraries into two separate libraries, which simplifies the
link arguments.  It also creates an "nf-config" command for Fortran
that replaces the "nc-config" command above.


Russ Rew                                         UCAR Unidata Program
address@hidden                      http://www.unidata.ucar.edu

Ticket Details
Ticket ID: OYI-144949
Department: Support netCDF
Priority: Normal
Status: Closed

NOTE: All email exchanges with Unidata User Support are recorded in the Unidata inquiry tracking system and then made publicly available through the web. If you do not want to have your interactions made available in this way, you must let us know in each email you send to us.