---------- Forwarded message ----------
From: Андрей Парамонов <cmr.pent@gmail.com>
Date: 2014-05-19 12:57 GMT+04:00
Subject: Linking to HDF5 library
To: mingw-users@lists.sourceforge.net


I'm writing a minimal demonstration program (that shows how to use my HDF5-based data format). The program is really simple:

#include "hdf5.h"

int main()
  hid_t file_id;
  hid_t dataset_id;
  hid_t attribute_id;
  hid_t space_id;
  hssize_t nscans, npeaks;
  double minmz, maxmz;

  printf("Opening MS.abf ... ");
  file_id = H5Fopen("MS.abf", H5F_ACC_RDONLY, H5P_DEFAULT);
  if(file_id > 0)
    return 1;

  dataset_id = H5Dopen(file_id, "rettime", H5P_DEFAULT);
  space_id = H5Dget_space(dataset_id);
  nscans = H5Sget_simple_extent_npoints(space_id);
  printf("Total scans: %lld.\n", nscans);

  dataset_id = H5Dopen(file_id, "specdata/mz", H5P_DEFAULT);
  space_id = H5Dget_space(dataset_id);
  npeaks = H5Sget_simple_extent_npoints(space_id);
  printf("Total MS peaks: %lld.\n", npeaks);

  attribute_id = H5Aopen(dataset_id, "min", H5P_DEFAULT);
  H5Aread(attribute_id, H5T_NATIVE_DOUBLE, &minmz);
  attribute_id = H5Aopen(dataset_id, "max", H5P_DEFAULT);
  H5Aread(attribute_id, H5T_NATIVE_DOUBLE, &maxmz);
  printf("M/z range: %f..%f.\n", minmz, maxmz);




What I want to do it to make sure that users (most of which are on w32) can compile and run the program as easily as possible. So, I don't want to resort to heavy artillery such as cmake or even makefiles. I believe for such a trivial program a simple gcc call should be enough.

I do not care much whether I link to *.lib file of *.dll file (however the latter seems easier to me -- but I'm no C specialist). It seems that *.h files along with *.dll file should be enough to provide the compiler and linker all needed information.

I'm running

>gcc test.c -I"C:\Progra~2\HDF_Group\HDF5\1.8.12\include" -L"C:\Progra~2\HDF_Group\HDF5\1.8.12\lib" -lhdf5 -otest.exe

where C:\Progra~2\HDF_Group\HDF5\1.8.12 is obtained from


but I get

C:\Users\paramon\AppData\Local\Temp\ccqrZOee.o:test.c:(.text+0x177): undefined reference to `H5T_NATIVE_DOUBLE_g'
C:\Users\paramon\AppData\Local\Temp\ccqrZOee.o:test.c:(.text+0x1c5): undefined reference to `H5T_NATIVE_DOUBLE_g'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\paramon\AppData\Local\Temp\ccqrZOee.o: bad reloc address 0x20 in section `.eh_frame'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

It seems that linker cannot find H5T_NATIVE_DOUBLE_g. However, it *is* in hdf5.dll: I can see it in Dependency Walker, and in fact I can use H5T_NATIVE_DOUBLE_g from Delphi (Pascal dialect) code.

Without H5T_NATIVE_DOUBLE -related lines, everything compiles and runs file.

What am I missing?

Best wishes,
Andrey Paramonov