In versions before 4.2, the Fortran netCDF library source was bundled with the C library source in one distribution, and it was possible to combine the libraries in a single library file. With version 4.2, the Fortran netCDF library for Fortran77 and Fortran90 APIs has been separated into its own source distribution, and should now be built as a separate library, after the C library is built and installed. This separation simplifies the building and use of the C and Fortran netCDF libraries and allows them to evolve independently.
Please note that in the example commands below, we assume use of a POSIX-standard shell, such as sh, bash, ksh, or zsh. If you are using csh instead, you will have to use the
setenv ENV_VARIABLE valuesyntax to set environment variables instead of the
ENV_VARIABLE=valuesyntax used in the examples that use a POSIX-standard shell. In either case, ${DIR1} is the value of the environment variable DIR1.
It will be easier to build the netCDF Fortran library if the C (and if needed, HDF5) libraries are built as shared libraries (the default), but you can also use static libraries, as described in a later section.
export LD_LIBRARY_PATH=${DIR1}/lib:${LD_LIBRARY_PATH}
CPPFLAGS=-I${DIR1}/include LDFLAGS=-L${DIR1}/lib ./configure --prefix=${DIR1}
Now you will only need to use something like
-L${DIR1}/lib -lnetcdff
to link Fortran software with the installed netCDF Fortran and C libraries.
If you can't build the C netCDF library as a shared library or if it has already been installed by someone else only as a static library (which means there are no libnetcdf.so files in the library directory where the netCDF C library was installed), then building and installing the Fortran netCDF libraries will be somewhat more complicated.
If you need to set the LD_LIBRARY_PATH (or DYLD_LIBRARY_PATH) environment variable, don't use the "sudo" command before the following "configure" or "make check" commands. Using "sudo" causes the LD_* environment variables to be ignored. You can use "sudo make install" as the last step, but you shouldn't need to use "sudo" before that.
CPPFLAGS="-I${DIR1}/include -I${DIR2}/include" \
LD_LIBRARY_PATH=${DIR1}/lib:${DIR2}/lib \
LDFLAGS="-L${DIR1}/lib -L${DIR2}/lib" \
LIBS="-lnetcdf -lhdf5_hl -lhdf5 -lz -lcurl" \
./configure --disable-shared --prefix=${DIR1}
If you use static libraries, you will need to use something like
-L${DIR1}/lib -lnetcdff -lnetcdf -L${DIR2}/lib -lhdf5_hl -lhdf5 -lz -curl -lm
to link Fortran software with the installed Fortran library, You could also use the "nf-config" utility installed in ${DIR1}/bin.