Previous: Error Handling, Up: Use of 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. Nevertheless, we provide here examples of how to compile and link a program that uses the netCDF library on a Unix platform, so that you can adjust these examples to fit your installation.
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 depends on the compiler, but is often .MOD. Most Fortran 90 compilers do not allow you to specify an alternative location for this file as you might the location of external libraries. The simplest solution, therefore, is to create a symbolic link from the directory in which your code resides to the location of the pre-compiled netCDF module. For example:
ln -s /usr/local/netcdf/src/f90/netcdf.mod .
You may then compile source files which reference netCDF constants or procedures.
f90 -c mymodule.f90
Unless the netCDF library is installed in a standard directory where the linker always looks, you must use the -L and -l options to link an object file that uses the netCDF library. For example:
f90 -o myprogram myprogram.o -L/usr/local/netcdf/lib -lnetcdf