Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Statically linking to HDF5 library raises linker errors #3560

Open
3 of 4 tasks
CSBVision opened this issue Sep 15, 2023 · 0 comments · May be fixed by #3563
Open
3 of 4 tasks

Statically linking to HDF5 library raises linker errors #3560

CSBVision opened this issue Sep 15, 2023 · 0 comments · May be fixed by #3563

Comments

@CSBVision
Copy link

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's modules directory
  • HDF5_INCLUDE_DIRS pointing to the include directory inside the HDF5 path (generated by its CMake install)
  • HDF5_C_LIBRARY pointing to the static lib/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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants