This archive contains answers to questions sent to Unidata support through mid-2025. Note that the archive is no longer being updated. We provide the archive for reference; many of the answers presented here remain technically correct, even if somewhat outdated. For the most up-to-date information on the use of NSF Unidata software and data services, please consult the Software Documentation first.
Hi Roy, This is just a repeat of the reply yesterday on the netcdfgroup mailing list, because I forgot to enter the response into our support system, where it will be searchable. In the future, you can just send to netcdfgroup if you want all 700+ members to see the question and answer, or just send to support-netcdf if you want only Unidata staff to see the question and respond to it. > 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 Russ Rew UCAR Unidata Program address@hidden http://www.unidata.ucar.edu Ticket Details =================== Ticket ID: CKK-939679 Department: Support netCDF Priority: Normal Status: Closed