This is an old revision of the document!
Building NetCDF, HDF4 and HDF5 on Windows
There are binaries available, and they're probably fine, but the headers are not, because HDF4 / HDF5 install different headers depending on which compiler they were built with (which in itself is a bug). Luckily, building them from source is fairly easy.
NetCDF
First, get the latest source (currently 4.0.1) from http://www.unidata.ucar.edu/software/netcdf/ and extract it in a convenient place, then configure, build and install:
$ LDFLAGS=-L/c/met.no/lib CPPFLAGS=-I/c/met.no/include ./configure --prefix=/c/met.no --disable-f90 --disable-examples $ make all install
Note the
--enable-shared
part; you can leave out --disable-f90
and --disable-examples
if you want, but keep --enable-shared
.
HDF4
First, get the latest source (currently 4.2r4) from http://www.hdfgroup.org/release4/obtain.html and extract it in a convenient place.
HDF4's autoconf infrastructure is a weird mix of too-old and too-new. Open configure.ac
, look for “Libtool initialization” (around line 660) and replace the following two lines
LT_INIT(dlopen) LT_OUTPUT
with these:
AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL
Next, there is a spot in configure.ac
that checks which OS you're running on and bails if it doesn't recognize it… which is stupid, because it controls code that is only used *only* if you want to use HDF4's own version of NetCDF, which we don't. We can work around this by changing cygwin
to mingw32
on line 695. It's wrong, but it doesn't matter, because the result is never used (see below).
Finally, in mfhdf/libsrc/Makefile.am
, there is a missing INCLUDES
line. We need to add the following line inside the if HDF_BUILD_XDR
block:
INCLUDES += -I$(top_srcdir)/mfhdf/xdr
Then regenerate everything:
$ aclocal $ libtoolize --copy --force $ autoheader $ automake --add-missing --copy --foreign $ autoconf
XXX automake warns about harmless since we don't build the Fortran interface
F77LINK
, check if that requires fixing.
Finally, configure, build and install:
$ LDFLAGS=-L/c/met.no/lib CPPFLAGS="-I/c/met.no/include -DNO_SYS_XDR_INC" ./configure --prefix=/c/met.no --disable-fortran --disable-netcdf $ make all install
The -DNO_SYS_XDR_INC
part fixes more xdr-related breakage.
You must specify --disable-netcdf
, otherwise HDF4 will clobber NetCDF's header files!
XXX I'm worried that the xdr stuff may cause more trouble down the line
HDF5
First, get the latest source (currently 1.8.3) from http://www.hdfgroup.org/HDF5/release/obtain5.html and extract it in a convenient place.
In HDF5 1.8.3, there are several issues we need to address before we can build the library.
note: the first two issues have been reported to the HDF Group and will be fixed in the next release.
The first is a bug in perform/sio_engine.c
: on line 376, replace mkdir
with HDmkdir
.
The second is that the test scripts use Winsock (ws2_32.lib
), but don't link against it. This can be fixed by running the following commands before configure
:
$ echo 'libh5test_la_LIBADD=-lws2_32' >>test/Makefile.am
The third is that several HDF5 libraries have a dependency on libhdf5
, but libtool isn't told about this. This can be fixed in the same manner as the ws2_32
issue:
$ echo 'libhdf5_cpp_la_LIBADD=$(LIBHDF5)' >>c++/src/Makefile.am $ echo 'libhdf5_hl_la_LIBADD=$(LIBHDF5)' >>hl/src/Makefile.am $ echo 'libhdf5_hl_cpp_la_LIBADD=$(LIBH5_HL)' >>hl/c++/src/Makefile.am
Finally, HDF5's configure.in
uses the LT_INIT
macro, which only works with very recent versions of automake. Edit configure.in
and replace these two lines:
LT_PREREQ([2.2]) LT_INIT([dlopen])
with this:
AC_LIBTOOL_DLOPEN AM_PROG_LIBTOOL
XXX alternative: use more recent autotools versions, but this has repercussions for all other components
Now we need to regenerate everything:
$ aclocal $ libtoolize --copy --force $ autoheader $ automake --add-missing --copy --foreign $ autoconf
The fourth and final issue is that C++ support is not enabled by default. To enable it, add –enable-cxx
to the configure
command line.
Finally:
$ LDFLAGS=-L/c/met.no/lib CPPFLAGS=-I/c/met.no/include ./configure --prefix=/c/met.no --enable-cxx $ make all install
TODO fix large file support!