Linker Error - C++ VS2019 MSBuild

Hi

TL;DR

I am attempting to run the Basics of HDF5 in C++ using VS2019 using MSBuild, not cmake.

I keep recieving linker errors.

Is it even possible to use the MSBuild system with HDF5? Or should I be using cmake?

Full Error

I am attempting to run the Basics of HDF5 in C++ using VS2019 using MSBuild, not cmake.

However I always recieved the following error when attempting to compile the first example:

1>Demo1.obj : error LNK2001: unresolved external symbol “public: static class H5::LinkCreatPropList const & const H5::LinkCreatPropList::DEFAULT” (?DEFAULT@LinkCreatPropList@H5@@2AEBV12@EB)
1>Demo1.obj : error LNK2001: unresolved external symbol “public: static class H5::FileAccPropList const & const H5::FileAccPropList::DEFAULT” (?DEFAULT@FileAccPropList@H5@@2AEBV12@EB)
1>Demo1.obj : error LNK2001: unresolved external symbol “public: static class H5::DSetAccPropList const & const H5::DSetAccPropList::DEFAULT” (?DEFAULT@DSetAccPropList@H5@@2AEBV12@EB)
1>Demo1.obj : error LNK2001: unresolved external symbol “public: static class H5::DSetCreatPropList const & const H5::DSetCreatPropList::DEFAULT” (?DEFAULT@DSetCreatPropList@H5@@2AEBV12@EB)
1>Demo1.obj : error LNK2001: unresolved external symbol “public: static class H5::PredType const & const H5::PredType::STD_I32BE” (?STD_I32BE@PredType@H5@@2AEBV12@EB)
1>Demo1.obj : error LNK2001: unresolved external symbol “public: static class H5::FileCreatPropList const & const H5::FileCreatPropList::DEFAULT” (?DEFAULT@FileCreatPropList@H5@@2AEBV12@EB)
1>C:\Users\admin\repos\hdf5Demos\bin\x64\Release\hdf5Demos.exe : fatal error LNK1120: 6 unresolved externals

  • I have installed the pre compiled binaries multiple times for hdf5 versions 1.12.0 and 1.10.7.

  • I have tried debug and release and am definitely using x64 at every stage

  • I have followed the “USING_HDF5_VS.txt” and added the include and lib dirs and appropriate libs

  • I have also tried compiling the source using cmake on my machine - which generates the libs fine. But still yields the same error when trying the Basic tutorials.


I have notcied that two of the libs mentioned in USING_HDF5_VS.txt are missing from the precompiled binaries “hdf5-1.10.7-Std-win10_64-vs16.zip” (Windows 10 64-bit pre-built binary for CMake VS 2019 C, C++, IVF).

  1. szip.lib
  2. zlib.lib

Although it is mentioned here that AEC replaced szip in 1.10.7 and when using the precompiled binaries for 1.12.0 these two libraries are both included. Eitherway I do not believe they are needed for these first examples.


The release notes mention a compiler flag which must be set if one intends to use the shared libs. This is in the release_docs. However when building from source using the the cmake GUI and CMake-hdf5-1.12.0 the following flag is not listed:

H5_BUILT_AS_DYNAMIC_LIB

However I intend to use the static libs so this again should not be a problem…

CMake will create an environment that will use MSBuild to build hdf5. But to build applications, it should not be needed. Seeing that when you built hdf5 from source and get the same result, it suggests there is something else causing a problem. The hdf5 binaries do provide the example project with scripts and instructions for using CMake. Perhaps you could try that - if successful then there will be VS project files that could provide info for using the MSBuild system directly.

Allen

Thank you @byrn for the reply. You were correct, the problem was a misunderstanding on my part.

Solution - Dynamic vs Shared Library confusion

In the lib folder there are two sets of files:

Static libraries, which have a “lib” prefix, eg: libhdf5.lib

Import libraries for using shared/dynamic libs, which have no prefix, eg: hdf5.lib

My error arose from mistaking the import libs for the static libs.

I solved this by either:

A.) Using the proper static libs, by modifiy the imported library names under:

Project > Properties > Linker > Input > additional dependancies

B.) Specifiy the compiler flag “H5_BUILT_AS_DYNAMIC_LIB” for using dynamic libs, in VS2019 this is under:

Project > Properties > C/C++ > Preprocessor > Preprocessor Defintions

A thought on USING_HDF5_VS.txt

The guide for using HDF5 with VS does not mention which kind of build is being performed: the libraries mentioned are for a dynamic build but the otherwise exhaustive steps fail to include setting of the compliler flag, see B above.

Perhaps it could be be mentioned that there are two types of library in the libs folder and potentially even include the two seperate methods of building: either specifiy compiler flag ( and how to do that in VS) or specifiy the static libs (and what they are really called).

My apologies if this is a widely used apporach to packaging which I am simply unaware of.

Thank you for your insight, we will attempt to include your suggestions in our next release, and in our development branches.

Allen

Hi @hd1714
I have been trying to build the pre-compiled binaries. But I couldnt find a way to locate the szip.lib and zlib.lib.
Could you please help me with the steps involved for generating the 2 missing libraries szip.lib & zlib.lib
Thank you