Hi all,
I'm having trouble using HDF5 with C++ using Visual Studio Pro 2015. Below is a message I sent to help@hdfgroup.org; I'm also sending it to this list in case someone else has run into the same problem.
The problem is, I can only link C++ programs when I use the static HDF5 libraries (libszip.lib, libzlib.lib, libhdf5.lib, libhdf5_cpp.lib) but not with the dynamic libraries (szip.lib, zlib.lib, hdf5.lib, hdf5_cpp.lib). When I link the static libraries, everything works fine -- links, builds an exe, and the exe works. When I try to link with the smaller dynamic libraries instead, I get unresolved symbol errors such as:
1>h5create.obj : error LNK2001: unresolved external symbol "public: static class H5::DataSpace const & const H5::DataSpace::ALL" (?ALL@DataSpace@H5@@2AEBV12@EB)
1>h5create.obj : error LNK2001: unresolved external symbol "public: static class H5::DSetCreatPropList const & const H5::DSetCreatPropList::DEFAULT" (?DEFAULT@DSetCreatPropList@H5@@2AEBV12@EB)
1>h5create.obj : error LNK2001: unresolved external symbol "public: static class H5::DSetMemXferPropList const & const H5::DSetMemXferPropList::DEFAULT" (?DEFAULT@DSetMemXferPropList@H5@@2AEBV12@EB)
1>h5create.obj : error LNK2001: unresolved external symbol "public: static class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT" (?DEFAULT@FileAccPropList@H5@@2AEBV12@EB)
1>h5create.obj : error LNK2001: unresolved external symbol "public: static class H5::FileCreatPropList const & const H5::FileCreatPropList::DEFAULT" (?DEFAULT@FileCreatPropList@H5@@2AEBV12@EB)
1>h5create.obj : error LNK2001: unresolved external symbol "public: static class H5::PredType const & const H5::PredType::NATIVE_INT" (?NATIVE_INT@PredType@H5@@2AEBV12@EB)
I am using Visual Studio Professional 2015 with the latest service packs. Here is the C++ info from Visual Studio's About-Help dialog:
Microsoft Visual Studio Professional 2015
Version 14.0.24720.00 Update 1
Microsoft .NET Framework
Version 4.6.01055
Installed Version: Professional
Visual C++ 2015 <<serial number>>
Microsoft Visual C++ 2015
I downloaded HDF5 1.8.16 from https://www.hdfgroup.org/HDF5/release/obtain5.html. Specifically I downloaded the Windows 64-bit version for "CMake VS 2015 C, C++, IVF 16", and installed it in the default directory under C:\Program Files.
I then created a new Visual Studio solution for a Win32 console application, and for the source code I used the C++ "create.cpp" example from the HDF site: https://www.hdfgroup.org/HDF5/doc/cpplus_RM/create_8cpp-example.html. In my Visual Studio project I added the include and lib directories to the compiler and linker paths, and added the HDF5 libraries (szip.lib, zlib.lib, hdf5.lib, hdf5_cpp.lib) to the linker "additional libraries" line. I left everything else as the defaults. When I compile, I get the unresolved symbol name errors mentioned at the top of this email. If I switch to the static libraries (libszip.lib, libzlib.lib, libhdf5.lib, libhdf5_cpp.lib) the errors go away.
To test my HDF5 installation, I downloaded CMake 3.4.3 and built the HDF5 Examples that came with the 1.8.16 distribution. That worked fine and I got 100% test cases passing (156 of 156, if I recall correctly). But, I notice that all the examples are in C rather than C++, so I suspect that is the root of the problem.
I looked into building the HDF5 libraries from source using CMake as suggested on the HDF site, but I see that while there are build scripts for VS2012 and VS2013, there is not one for VS2015. I am new to CMake and didn't feel comfortable taking that on (yet) but I suppose I should learn.
Note that I also set up a Linux box (Mint 17.4), downloaded the HDF5 binary distribution for the 2.6 kernel, installed it and built the same sample application (create.cpp) without any trouble. For that I was able to link with both the dynamic .so files and the static .a files. So my problem seems to be on Windows only.
Any help is appreciated. Thanks!
Terry McKiernan