[Fortran] Compiling and Linking with 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 (note 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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.