Is it possible to build Slicer with custom HDF5 library? I mean I would like to build HDF5 separetely from SLicer
I can see that VTK and ITK somehow use it but there is no hdf5_D.lib or hdf5_hl_D.lib in Slicer build dir (VTK-build and ITK-build folders)
For now when I try to use my custom HDF5 lib in my loadable module I get link errors like: h5core.obj:-1: error: LNK2019: unresolved external symbol itk_H5open referenced in function “public: __cdecl HighFive::AtomicType::AtomicType(void)” (??0?$AtomicType@H@HighFive@@QEAA@XZ) [C:\S\extensions\build-MSV-Qt_msvc2019_64-Debug\MSVCore\msvcore.vcxproj]
Slicer does not use HDF5 directly, only via its dependent libraries - ITK and VTK. You should be able to pass down your custom HDF5 library the same way as it is done for zlib (check out *.cmake files in the SuperBuild folder), but you would only need to do this if you wanted ITK and VTK to use your custom HDF5, which is probably not what you need.
If you want your module to use custom HDF5 then you can build your custom HDF5 along with other modules and libraries in your extension (you can use the superbuild extension template). Both ITK and VTK use name mangling when building HDF, so there will be no conflicts.
I’m just curious, why do you need to use a custom HDF5 library?
I’m sorry I confused you. The word custom is inapropriate.
I need HDF5 library configured with almost any CMake settings. I would like to try to use the same HDF5 library that VTK or ITK uses but I didn’t find HDF5 library with names something like hdf5_D.lib in VTK-build and ITK-build subfolders.
I have written some small core shared lib that uses HDF5 via HighFive wrapper header only C++ library. As I’m not going to display this core in Slicer app and in the same time many of my loadable modules use this core, I decided to make this core as a subfolder in my extension and not to make a module from this core. And modules of this extension simply links to this core.
When I build this I get many errors like this: h5core.obj:-1: error: LNK2019: unresolved external symbol itk_H5open referenced in function “public: __cdecl HighFive::AtomicType::AtomicType(void)” (??0?$AtomicType@H@HighFive@@QEAA@XZ) [C:\S\extensions\build-MSV-Qt_msvc2019_64-Debug\MSVCore\msvcore.vcxproj]
I decided that the problem is that VTK and ITK uses HDF5 libs and I also include staticlibhdf5_D.lib and libhdf5_hl_D.lib
Well the problem is that I can’t link HDF5 to my core shared lib which is subfolder of extension and there is some custom HDF5, probably I would like to use one of the latest HDF5 lib
Probably you just need to link ITK’s HDF5 library to your target. In general, if you use ITK’s or VTK’s name-mangled HDF5 then you need to link the corresponding ITK/VTK library.
If ITK/VTK is built so that HDF5 library is not exported as a publicly usable target outside ITK/VTK then you can build any HDF5 library implementation yourself, as part of your extension superbuild, and use that. See for example SlicerJupyter extension, which builds and uses several third-party libraries.
As I’m studying Slicer I’m trying now to simply build HDF5 lib with SuperBuild. So to do this I guess I should work only with CMake. Is there the simplest example showing how to build third party C++ external library with Slicer superbuild?
I tried to follow the example you gave with Slicer Jupiter but somehow my code doesn’t launch build step for HDF5 even if in general build is succesfull.
Thank you. I’ve found my mistake. I should have been look more precisely at ExternalProject_Add(...) CMake parameters.
Now inside my module the command find_package(hdf5 REQUIRED) fails with error:
CMake Error at C:/S/extensions/Proba-build/HDF5-build/hdf5-config.cmake:25 (message): File or directory C:/S/extensions/bin referenced by variable HDF5_TOOLS_DIR does not exist !
Here C:/S/extensions/bin should be C:\S\extensions\Proba-build\HDF5-build\tools but I can’t understand why it points to wrong directory. If you had some experience of superbuild HDF5 did you encounter similar error?
I use hdf5-1_12_0 git tag, tomorrow I will try some other tag
Here it is the repository: https://github.com/KerimMatlab/Proba/tree/main
I’m ashamed that it has strange name. I just started exploring slicer and didnt think that I would create repo from this test extension
I’ve had a look. You need to use hdf5 instead of HDF5 (this is how the library calls itself in its CMake config file) and not specify NO_MODULE when you find the package: https://github.com/KerimMatlab/Proba/pull/1/files
I ve figured out that this error is the result of the fact that find_package(hdf5 REQUIRED) produces the message:
RUNNING KKK
CMake Warning (dev) at C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindPackageHandleStandardArgs.cmake:424 (message):
The package name passed to find_package_handle_standard_args (HDF5) does
not match the name of the calling package (hdf5). This can lead to
problems in calling code that expects find_package result variables
(e.g., _FOUND) to follow a certain pattern.
Call Stack (most recent call first):
C:/Qt/Tools/CMake_64/share/cmake-3.19/Modules/FindHDF5.cmake:975 (find_package_handle_standard_args)
C:/S/d/VTK/CMake/FindHDF5.cmake:9 (include)
KKK/CMakeLists.txt:10 (find_package)
This warning is for project developers. Use -Wno-dev to suppress it.
– Could NOT find HDF5 (missing: HDF5_LIBRARIES HDF5_INCLUDE_DIRS) (found version “”)
In my code now there no upper case variables HDF5 only smaller hdf5