Search code examples
visual-studiocmakehdf5

Using pre-compiled HDF5 libraries with CMake under Windows


I would like to use the pre-compiled HDF5 libraries in a CMake project which should be platform independent. The Linux version works very well, under Windows different problems occurred on different systems.

Question #1: Problem on Windows Server 2008, Visual Studio Ultimate 2012

On this machine, CMake 3.7.2 is used to generate the Visual Studio project. This works fine, the versions 1.8.18 and 1.10.1 of the HDF5 libraries are installed and found. The problem appears during compilation, where the header file inttypes.h is not found. This header file belongs somewhat to the C99 standard, which is not supported by some Visual Studio compiler versions. Are there any remedies to this problem?

Question #2: Problem on Windows 10, Visual Studio Enterprise 2017

Here, I installed HDF5 1.10.1 and CMake 3.10 and tried to build my simple example CMake script:

cmake_minimum_required(VERSION 3.2.2)
project(hdf5test)
find_package(HDF5 REQUIRED COMPONENTS C CXX NAMES hdf5)

I followed the advice in USING_HDF5_CMake.txt and set the HDF5_DIR environment variable. But whatever I try, the error:

Could not find a configuration file for package "HDF5" that is compatible with requested version "".

The following configuration files were considered but not accepted: C:/Program Files/HDF_Group/HDF5/1.10.1/cmake/hdf5-config.cmake, version: 1.10.1 (64bit)

always appears. Now I am confused, looks like CMake was on the correct trace but ignored the correct library for some reason. Any ideas why this happens?

Question #3: Problem on Windows 10 (update)

I somehow managed to get the code compiling on the same machine as in #2. The quick fix was to use the module mode of CMake's find_package (the NAMES parameter activates this mode, after removing this parameter I could generate and build the Visual Studio solution.

Then, I added a short C++ code snippet which creates a HDF5 file:

#include "H5Cpp.h"
int main(void)
{
    H5::H5File file("test.hdf", H5F_ACC_TRUNC);
}

This code compiles, but when I run it, it gives me the error:

The procedure entry point H5Pset_virtual could not be located in the dynamic link library [...]\hdf5_cpp.dll.

Any ideas?

Related:


Solution

  • This answer is the summary of the insights from the comments for later reference. Thanks to vre and the people in the HDF5 forum for their contributions.

    #1

    The problem here was that the HDF5 library in the Windows installer was configured so that it assumes the presence of certain header files. One may adjust certain defines to get it right (see the discussion in the HDF5 forum), but the clean way is to compile the HDF5 library from scratch.

    #2

    No solution here. Hence I switched to the module mode of CMake, which found the HDF5 library on every system.

    #3

    There was another version of the hdf5.dll in the PATH variable. MATLAB and ParaView for example cause such behavior. A solution could be static linking. To achieve this, one has to get the PATH right at least at compile time. Maybe there is a CMake feature that gives an absolute path to the linker.

    Still not sure what the best solution is to get safely through the DLL hell. I guess it is a rather general problem, but pointers are welcome anyway.