Re: [netcdfgroup] Building netcdf-4 programs with F90

Hi Roy,

> I am finally getting a chance to look at the f90 interface to  
> netcdf-4.  I will use gfortran for compatibility.  I am reading the  
> Makefile correctly that I should use:
> 
> gfortran -g -O2
> 
> and that libnetcdf libnetcdff and both hdf libs need to be linked in,  
> or are the hdflibs already linked to libnetcdf?  Is there a preferred  
> order to the links?

By default, you don't need libnetcdff, which is a separate Fortran
library required only when you specify --enable-separate-fortran or
--enable-shared flags to the configure script.

The --enable-separate-fortran flag will cause the Fortran 77 and Fortran
90 APIs to be built into a separate library, instead of being included
in the C library.  This is useful for supporting more than one Fortran
compiler with the same netCDF C library.  This is turned on by default
for shared library builds.

The --enable-shared flag will build shared libraries (as well as static)
on platforms that support them.

If you have enabled shared libraries or specified a separate Fortran
library, you should link with the Fortran library first, since it calls
functions in the C library, as in

  -L/usr/local/netcdf -lnetcdff -lnetcdf

Because the netCDF-4 library calls HDF5 functions, HDF5 libraries need
to be specified after the netCDF library, as in

  -L/usr/local/netcdf -lnetcdff -lnetcdf -L/usr/local/hdf -lhdf5_hl -lhdf5

This finds functions in both the HDF5 high-level library and the HDF5
core library, and the libraries should be mentioned in that order.

It would be simpler if you define an environment variable or macro for
the needed libraries, as you would do in a Makefile.

Another approach is to define a customized compiler command (which might
be an alias or a simple shell script) so you only have to get the
location of the include files and libraries right once and can change
them in one place.  We may eventually provide such a convenience command
if we can figure out how to make it flexible enough, analogous to the
h5cc script included in HDF5 software.

Eventually we would like to bundle the software to make linking simpler,
but that will have to wait for a future release.

--Russ


  • 2008 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: