There are two HDF formats, HDF4, and HDF5 which each have their own libraries and drivers. HDF4 is more common, but HDF5 is the next generation format.

Building with HDF4

NCSA HDF library can be downloaded from the The NCSA HDF Home Page at the the National Center for Supercomputing Applications. HDF 4.2r1 is generally the preferred version if working from source. The szip option is not widely used, and may be omitted for simplicity.

If your OS distribution already contains prebuilt HDF library you can use one from the distribution.

Open File Limits

Please note, that NCSA HDF library compiled with several defaults which is defined in hlimits.h file. For example, hlimits.h defines the maximum number of opened files:

#   define MAX_FILE   32

If you need open more HDF4 files simultaneously you should change this value and rebuild HDF4 library (there is no need to rebuild GDAL if it is already compiled with HDF4 support).

Incompatibility with NetCDF Libraries

The HDF4 libraries include an implementation of the netcdf api which can access hdf files. If building with HDF4 and NetCDF it is necessary to build the HDF library with this disabled.

If using Ubuntu/Debian? dev packages you must make sure that the libhdf4-alt-dev package is installed instead of the libhdf4-dev package.

If building HDF4 manually you have to add "--disable-netcdf" to "configure" and HDF4 will move its embedded NetCDF functions in a different private namespace to avoid name clashes.

./configure --disable-netcdf --disable-fortran

If building older versions of HDF4 (before HDF4.2r3) the macro HAVE_NETCDF needs to be defined instead. This can be accomplished by configuring the HDF4 libraries as follows:

export LIBS="-lm"
./configure --disable-fortran

The -fPIC and LIBS may not be necessary on all platforms. Without this fix either GDAL will crash intermittently when accessing netcdf files, or the build of GDAL will fail.

Additional linux workaround

if rebulding hdf is not an option you can also preload the netCDF library. gdalinfo

Potential conflicts with internal libz

The HDF4 libraries depend on libz library. If you build HDF4 from sources, you most likely use libz library already installed in your system. Then, when you run GDAL ./configure script using option --with-libz=internal requesting GDAL to use its internal version of libz, you may notice that HDF4 support is not enabled as you expected. This might signal a conflict between internal libz and the version installed in you system against which HDF libraries were linked. More detailed description of the problem and its symptoms can be found in summary of Ticket #1955.

Building with HDF5

Building on Windows with MSVC

If your HDF5 source directory does not have an /include directory in its root, then you must do the following:

  • in nmake.opt add a pointer to the directory containing the headers, such as
        HDF5_INCLUDE =  $(HDF5_DIR)\src
  • modify the EXTRAFLAGS parameter in gdal\frmts\hdf\ to include this new definition, such as:
    • note that if you build against the static HDF5 lib (libhd5.lib) you will have to use the "-D_HDF5USEDLL_" as above; but if you build against the dynamic HDF5 lib (hdf5.lib) you will have to use the "-DH5_BUILT_AS_DYNAMIC_LIB" switch instead
  • You can test this by executing the following in gdal\frmts\hdf:
        nmake /f

Open Tickets

HDF - Georeferencing for ASTER HDF_EOS products
Get hdf band, inverse data set dimensions
patch for frmts/HDF4 (HDF_GLOBAL#{spatial_ref/GeoTransform})
HDF4 reading MISR Level 3 with incorrect dimension
HDF4 Update In Place Support
[PATCH] HDF4, IReadBlock() and GDA_Update
[""PATCH""] HDF5 : cannot read/convert some multi-band multi-image dataset
subdatasets not read in a HDF file
GDAL reports incorrect longitude coordinates in HDF5 files as GCPs
[] HDF input, ENVI output; unable to open in ENVI
PATCH: DODS driver can now read 3-D datasets, metadata, projection, remote NetCDF files
Implement support for HDF-EOS5
Support additional USGS coordinate systems
Problems reading older MODIS Sea Ice Extent and IST Daily L3 Global 4km EASE-Grid Day HDF data
Enhancement in HDF4/HDF5 Drivers for GDAL
Update frmts/hdf4/hdfeos with HDF-EOS2.19 or newer

Last modified 9 months ago Last modified on May 10, 2016 7:29:24 AM