- To: netcdf <netcdfgroup@xxxxxxxxxxxxxxxx>
- Subject: [netcdfgroup] hdf5 dependency of libnetcdf
- From: Magnus Hagdorn <Magnus.Hagdorn@xxxxxxxx>
- Date: Tue, 02 Jun 2009 17:32:48 +0100
Hi there when compiling netCDF with HDF5 backend it is quite a pain to tell users they need to also link to libhdf5 and libhdf5_hl. The attached patch to libsrc4/Makefile.am tells libtool to produce a dynamic library which automatically links to the required dependencies. So a user only needs to link to libnetcdf and the linker resolves the dependencies for libhdf5 and friends. I have also attached a script which reruns all the autotools in the correct order to rebuild the build system. This file is taken from the gimp project. I hope someone else finds this patch useful and I'd be delighted if it went into the netCDF library. Regards magnus -- The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.
Attachment:
autogen.sh
Description: application/shellscript
--- ../netcdf-4.0-vanilla/libsrc4/Makefile.am   2008-06-09 17:32:46.000000000 
+0100
+++ libsrc4/Makefile.am 2009-06-02 16:57:39.032942353 +0100
@@ -19,19 +19,16 @@
 # If the user specified a root location for HDF5, use it.
 if USE_HDF5_DIR
 AM_CPPFLAGS += -I@HDF5DIR@/include
-AM_LDFLAGS += -L@HDF5DIR@/lib
 endif
 
 # If the user specified a root location for ZLIB, use it.
 if USE_ZLIB_DIR
 AM_CPPFLAGS += -I@ZLIBDIR@/include
-AM_LDFLAGS += -L@ZLIBDIR@/lib
 endif
 
 # If the user specified a root location for SZLIB, use it.
 if USE_SZLIB_DIR
 AM_CPPFLAGS += -I@SZLIBDIR@/include
-AM_LDFLAGS += -L@SZLIBDIR@/lib
 endif
 
 # Tell automake that netcdf.h is a header file we want to install.
@@ -63,6 +60,10 @@
 TST_V2 = tst_v2 
 endif
 
+# add the HDF5 libraries
+libnetcdf_la_LIBADD += -lhdf5_hl -lhdf5
+libnetcdf_la_LDFLAGS = -L@HDF5DIR@/lib -L@ZLIBDIR@/lib -L@SZLIBDIR@/lib
+
 # Netcdf-4 source.
 libnetcdf_la_SOURCES = nc4attr.c nc4internal.c nc4var.c netcdf3.h      \
 nc4dim.c nc4internal.h ncfunc.c nc4file.c netcdf.h error.c error.h     \
@@ -80,7 +81,7 @@
 
 endif # !BUILD_SEPARATE_FORTRAN
 # These linker flags specify libtool version info.
-libnetcdf_la_LDFLAGS = -version-number 5:0:0
+libnetcdf_la_LDFLAGS += -version-number 5:0:0
 
 # These programs are all built for make check in this directory.
 my_tests = tst_h_files tst_h_atts tst_h_atts2 tst_h_vars tst_h_vars2   \
@@ -103,7 +104,7 @@
 # sort out the MAX_INT problem. - Ed)
 
 # These linker flags will be applied to all test program compiles.
-LDADD = ${lib_LTLIBRARIES} -lhdf5_hl -lhdf5
+LDADD = ${lib_LTLIBRARIES} 
 
 # This header is used by all test programs.
 noinst_HEADERS = nc_tests.h
   