title: Use HDF5 from minGW on windows
body: <p>I'm trying to compile and link to HDF5 with a Fortran program, but I'm getting a run-time error. I've followed closely the procedure described in the answer to this question</p>
  
  <p><a href="https://stackoverflow.com/questions/20048938/use-hdf5-from-intel-fortran-on-windows">Use HDF5 from intel fortran on windows</a></p>
  
  <p>I've set PATH in the environment variables instead of setting them in visual studio. I moved all of the generated .mod and .lib files to the mod and lib folders in my project folder.</p>
  
  <p>From the command prompt, my compiler config looks like</p>
  
  <pre><code> gfortran --version
   GNU Fortran (x86_64-posix-seh-rev0, Built by MinGW-W64 project) 4.9.2
   gmake --version
   GNU Make 3.81
  </code></pre>
  
  <p>And my makefile looks like</p>
  
  <pre><code> ifdef SystemRoot
       PATHSEP2 = \\
   else
       PATHSEP2 = /
   endif
   PS = $(strip $(PATHSEP2))
  
   OBJ_DIR = obj
   MOD_DIR = mod
   LIB_DIR = lib
  
   FC      = gfortran
   FCFLAGS = -I$(MOD_DIR) -g -Wall
   FLFLAGS = -I$(MOD_DIR) -L$(LIB_DIR) -l$(LIB_DIR)hdf5_fortran
  
   SRCS_F = testHDF5.f90
  
   TARGET = testHDF5
  
   all: $(TARGET)
  
   testHDF5: testHDF5.f90 
    $(FC) -o $@ testHDF5.f90 $(FLFLAGS)
  
   $(OBJ_DIR)$(PS)%.o: %.f90
    $(FC) $(FCFLAGS) -c -o $@ $&lt;
  </code></pre>
  
  <p>I've changed the hdf5_fortran.lib to libhdf5_fortran.lib because of what I read here</p>
  
  <p><a href="http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use" rel="nofollow noreferrer">http://www.mingw.org/wiki/specify_the_libraries_for_the_linker_to_use</a></p>
  
  <p>When I run gmake, I get</p>
  
  <pre><code> gfortran -o testHDF5 testHDF5.f90 -Imod -Llib -llibhdf5_fortran
  </code></pre>
  
  <p>And when I try to run the executable, a window pops up that says "The application was unable to start correctly (0xc000007b). Click OK to close the application."</p>
  
  <p>This link</p>
  
  <p><a href="http://www.solveinweb.com/solved-the-application-was-unable-to-start-correctly-0xc000007b-click-ok-to-close-the-application/" rel="nofollow noreferrer">http://www.solveinweb.com/solved-the-application-was-unable-to-start-correctly-0xc000007b-click-ok-to-close-the-application/</a></p>
  
  <p>Suggests that it is due to incompatibility of 32-bit to 64-bit. I'm using a 64-bit machine, and I did download a 32-bit version of CMake, but only because there doesn't seem to be an available version for 64-bit machines. In addition, this link</p>
  
  <p><a href="http://www.cmake.org/pipermail/cmake/2010-September/039375.html" rel="nofollow noreferrer">http://www.cmake.org/pipermail/cmake/2010-September/039375.html</a></p>
  
  <p>Suggests that it shouldn't matter. So my question is, where did I go wrong? Are there any glaring mistakes with what I've shown so far?</p>
  
  <p>UPDATE:</p>
  
  <p>I found out that the runtime error was due to not specifying a path, in this case HDF5_DIR. In the USING_HDF5_CMAKE document, it says to specify the environment variable</p>
  
  <pre><code> HDF5_DIR=C:/Program Files/HDF_Group/HDF5/1.8.x/cmake/hdf5
  </code></pre>
  
  <p>Which fixed the problem of the application crashing at the very start. But now, I'm getting the error</p>
  
  <pre><code> HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0:
     #000: C:\Users\Charlie\Downloads\CMake\hdf5-1.8.14\src\H5D.c line 167 in H5Dcr
   eate2(): not a datatype ID
       major: Invalid arguments to routine
       minor: Inappropriate type
   HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0:
     #000: C:\Users\Charlie\Downloads\CMake\hdf5-1.8.14\src\H5D.c line 415 in H5Dcl
   ose(): not a dataset
       major: Invalid arguments to routine
       minor: Inappropriate type
  </code></pre>
  
  <p>I suppose the first error</p>
  
  <pre><code> HDF5-DIAG: Error detected in HDF5 (1.8.14) thread 0:
     #000: C:\Users\Charlie\Downloads\CMake\hdf5-1.8.14\src\H5D.c line 167 in H5Dcr
   eate2(): not a datatype ID
       major: Invalid arguments to routine
       minor: Inappropriate type
  </code></pre>
  
  <p>Is the most important one since that may trigger later ones. According to this thread</p>
  
  <p><a href="http://hdf-forum.184993.n3.nabble.com/HDF5-Fortran-Fail-to-execute-of-a-basic-F90-program-td4026778.html" rel="nofollow noreferrer">http://hdf-forum.184993.n3.nabble.com/HDF5-Fortran-Fail-to-execute-of-a-basic-F90-program-td4026778.html</a></p>
  
  <p>It is suggested that the same compiler is used to build the library as building the fortran source code (if I'm not mistaken). During the build using CMake, I specified to use MinGW, which I believe is used during both builds, right?</p>
  
  <p>Again, any help on this is greatly appreciated.</p>