Unidata - To provide the data services, tools, and cyberinfrastructure leadership that advance Earth system science, enhance educational opportunities, and broaden participation. Unidata
         
  advanced  
 

Previous: Error Handling, Up: Use of the NetCDF Library


1.7 Compiling and Linking with the NetCDF Library

Details of how to compile and link a program that uses the netCDF C or Fortran interfaces differ, depending on the operating system, the available compilers, and where the netCDF library and include files are installed.

Every Fortran 90 procedure or module which references netCDF constants or procedures must have access to the module information created when the netCDF module was compiled. The suffix for this file is “MOD” (or sometimes “mod”).

Most F90 compilers allow the user to specify the location of .MOD files, usually with the -I flag. (Some compilers, like absoft, use -p instead).

     f90 -c -I/usr/local/include mymodule.f90

Starting with version 3.6.2, another method of building the netCDF fortran libraries becomes available. With the –enable-separate-fortran option to configure, the user can specify that the C library should not contain the fortran functions. In these cases an additional library, libnetcdff.a (not the extra “f”) will be built. This library contains the fortran functions.

For more information about configure options, See Specifying the Environment for Building.

Building separate fortran libraries is required for shared library builds, but is not done, by default, for static library builds.

When linking fortran programs without a separate fortran library, programs must link to the netCDF library like this:

     f90 -o myprogram myprogram.o -L/usr/local/netcdf/lib -lnetcdf
 
 
  Contact Us     Site Map     Search     Terms and Conditions     Privacy Policy     Participation Policy
 
National Science Foundation (NSF) UCAR Office of Programs University Corporation for Atmospheric Research (UCAR)   Unidata is a member of the UCAR Office of Programs, is managed by the University Corporation for Atmospheric Research, and is sponsored by the National Science Foundation.
P.O. Box 3000     Boulder, CO 80307-3000 USA     Tel: 303-497-8643     Fax: 303-497-8690