1

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:

carlosvalderrama
  • 465
  • 1
  • 6
  • 22
  • 1
    We include HDF5 by setting the HDF5_DIR as a CMake variable and later use `find_package(HDF5 COMPONENTS CXX CXX_HL NO_MODULE REQUIRED static)` to link to the static libraries. As of updated question #3, maybe there's an older hdf5 DLL in the path? Try prepending the HDF5 DLL path explicitely in the VS Solution Explorer->Properties->Configuration Properties->Debugging->Environment setting. – vre Feb 07 '19 at 18:00
  • The environment variable is `HDF5_ROOT` – Pierre de Buyl Feb 08 '19 at 08:33
  • OK, I have tried several things without any success. What I have learned so far: find_package offers two signatures, the basic module mode and the advanced config mode. In module mode the HDF5 library is found, but the error at startup is persistent. In config mode the CMake variable ${HDF5_LIBRARIES} is not populated and I get linker errors. – carlosvalderrama Feb 08 '19 at 18:20
  • @vre: Your command uses the config mode, where I get linker errors. – carlosvalderrama Feb 08 '19 at 18:23
  • @PierredeBuyl: For module mode indeed the variable HDF5_ROOT must be set if required. For config mode, the variable HDF5_DIR is used (and overwritten in the find process). – carlosvalderrama Feb 08 '19 at 18:24
  • @vre: I should have mentioned that the error message explicitly states the path of the library and the path is correct. – carlosvalderrama Feb 08 '19 at 18:51
  • 1
    IIRC, I always used the config mode and used the library signatures found in HDF5_DIR/FindHDF5.cmake and HDF5-config.cmake, e.g. ${HDF5_CXX_STATIC_LIBRARY} ${HDF5_CXX_HL_STATIC_LIBRARY}. Did you try to use the target names mentioned in FindHDF5.cmake, e.g. hdf5_cpp or hdf5 in your case, in your `target_link_libraries` call? – vre Feb 08 '19 at 19:36
  • @vre Thanks for the hint. Apparently, the ${HDF5_LIBRARIES} variable is not populated in config mode. Now both approaches (module mode and config mode) lead to successful compilation and linking, but the startup error remains. – carlosvalderrama Feb 11 '19 at 19:15
  • @vre And finally, you were correct with your initial guess: I had to rearrange the order of the entries in PATH to get it working. After close inspection, I found another HDF5 library in an installation of Paraview. Makes me wonder how those clashes are usually avoided, but this might become a separate question. Thanks very much for your help! If you create an answer, I'd be happy to accept it. – carlosvalderrama Feb 11 '19 at 20:20

1 Answers1

1

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.

carlosvalderrama
  • 465
  • 1
  • 6
  • 22