Description
System information (version)
- OpenCV => 4.8.0
- Operating System / Platform => Windows 64 Bit
- Compiler => Visual Studio 2022
Detailed description
We recently tried to compile OpenCV's HDF module, which only works by default while linking to a shared HDF5 libary. However, as it's a single-module dependendy, statically linking to HDF5 is advantageous here. Still, this results in linker errors caused by hardcoded configuration options for shared library linking. In particular, the flags inside the Windows branch in the CMakeLists.txt
defined by
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB -D_HDF5USEDLL_)
result in linker errors. After removing them, only a linker error from the missing ShLwApi.Lib
is raised.
These two issues can be resolved by extending above line to
if(HDF5_C_LIBRARY MATCHES "libhdf5.lib$")
set(HDF5_LIBRARIES "${HDF5_LIBRARIES};ShLwApi.Lib")
else()
add_definitions(-DH5_BUILT_AS_DYNAMIC_LIB -D_HDF5USEDLL_)
endif()
and compiling works with both, shared and static library linking to HDF5.
Still, we wanted to discuss this as an issue first before creating a respective PR.
Steps to reproduce
After cloning OpenCV's main and contrib repositories, run CMake with the following flags:
OPENCV_EXTRA_MODULES_PATH
pointing to the contrib'smodules
directoryHDF5_INCLUDE_DIRS
pointing to theinclude
directory inside the HDF5 path (generated by its CMake install)HDF5_C_LIBRARY
pointing to the staticlib/libhdf5.lib
in the same path
Now, building of the HDF module raises a bunch of linker error.
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues,
forum.opencv.org, Stack Overflow, etc and have not found any solution - I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files: videos, images, onnx, etc