---------- 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


Hello!

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)
    printf("done.\n");
  else{
    printf("error!\n");
    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);
  H5Sclose(space_id);
  H5Dclose(dataset_id);

  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);
  H5Sclose(space_id);

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

  H5Dclose(dataset_id);

  H5Fclose(file_id);

  return;


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

http://www.hdfgroup.org/ftp/HDF5/releases/hdf5-1.8.12/bin/windows/hdf5-1.8.12-win32-vs10shared.zip

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