Building SimpleITK as Shared Libs with System HDF5

Hello,

I am trying to build SimpleITK ( branch master ) with a system version of HDF5 ( v1.10.5 )
I cloned ITK ( on branch master ), and successfully built it while linking to the system HDF5.

When I try to configure/generate SimpleITK with the system ITK and system HDF5, I get the following error:

 CMake Error at Code/IO/src/CMakeLists.txt:21 (add_library):
   Target "SimpleITKIO" links to target "hdf5::hdf5_cpp" but the target was
   not found.  Perhaps a find_package() call is missing for an IMPORTED
   target, or an ALIAS target is missing?

 CMake Error at Code/IO/src/CMakeLists.txt:21 (add_library):
   Target "SimpleITKIO" links to target "hdf5::hdf5" but the target was not
   found.  Perhaps a find_package() call is missing for an IMPORTED target, or
   an ALIAS target is missing?

I have used RelWithDebInfo symbols for HDF5, ITK, and SimpleITK in case that makes a difference.
I am running Centos7 , with gcc 7.3.1

I’ve searched for a few days now, and am unable to get past this. Any help is greatly appreciated.

1 Like

Using the fix from https://github.com/InsightSoftwareConsortium/ITK/pull/1503
I was able to move past this and install SimpleITK with BUILD_SHARED_LIBS ON to an install path outside of the build tree.

I added the find_package(Threads) and gtest_disable_pthreads ON to the ITK and SimpleITK CMakeLists.txt. It allows me to get past the Threads::Threads error. More details below.

Please advise if there is a better way to do this.

Using :

  • CMake v3.19.4
  • HDF5 1.10.5
  • ITK v5.1.2
  • SimpleITK v2.0.2
  • SWIG 4.1.0
  • LUA 5.3.5
  1. Cloned ITK ( v5.1.2 ) and modified the ITK/CMakeLists.txt with :
    #----------------------------------------------------------------------
    Generate ITKConfig.cmake for the build tree.
    +find_package(Threads)
    +set(gtest_disable_pthreads ON CACHE INTERNAL “”)

and installed with the following cmake config:

*  CMAKE_BUILD_TYPE                 RELEASE
*  CMAKE_SKIP_INSTALL_RPATH         ON
*  CMAKE_SKIP_RPATH                 ON
*  Module_ITKIOTransformMINC        ON
*  Module_ITKReview                 ON
*  Module_SimpleITKFilters          ON
*  Module_SimpleITKFilters_GIT_TA   a2101c137d2c99cf32b2d9600b1e4c3e14722a16
*  ITK_USE_SYSTEM_LIBRARIES         ON
*  ITK_USE_SYSTEM_HDF5              ON
*  CMAKE_PREFIX_PATH                /opt/ITK-prefix
  1. Install SWIG and LUA. I used versions 4.1.0, and 5.3.5 respectively
  1. Cloned SimpleITK( v2.0.2 ) and modified the CMakeLists.txt :

    message(STATUS “Building SimpleITK version “${SimpleITK_VERSION}””)
    +find_package(Threads)
    +set(gtest_disable_pthreads ON CACHE INTERNAL “”)

installed with the following :

* CMAKE_BUILD_TYPE            Release
* CMAKE_INSTALL_PREFIX        /opt/sitk-prefix
* ITK_DIR                     /opt/ITK-prefix/lib/cmake/ITK-5.1
* CMAKE_SKIP_INSTALL_RPATH         ON
* CMAKE_SKIP_RPATH                 ON
* SWIG_DIR                   /opt/swig
* SWIG_EXECUTABLE            /opt/swing/bin
* SimpleITK_LUA_EXECUTABLE   /opt/lua/bin/lua

I was then able to dynamically link these libraries to my app.

( Additional: if having hdf5 linking issues the following helped https://gitlab.kitware.com/cmake/cmake/-/issues/18560#note_881956
https://github.com/InsightSoftwareConsortium/ITK/pull/1696#issuecomment-624791166 )

1 Like

Great job tracking down the problem and following up with posting the solution :clap:

Have you checked building if the ITK patch is still needed if you use ITK 5.2rc1?

If you are installing SimpleITK into the system, then it frequently makes since to have CMAKE_SKIP_INSTALL_RPATH=ON.

The initial post reports the error with hdf5::hdf5 missing, but the follow up mentions Threads::Threads and GTest. Have you enabled testing when building SimpleITK?

I suspect that the system HDF5 is not correctly exporting the transitive “Threads::Threads” dependency.

Thanks, thought it might help someone down the road.

I will give ITK 5.2rc1 a shot, as these build instructions will be needed by other devs on my project, and in our CICD system. Hopefully it works as ideally, I don’t want to make any changes to a cloned library, other than it’s CMake config.

No, I had BUILD_TESTING OFF.

Though you bring up a good point about the transitive “Threads::Threads” dependency. We had some issues installing HDF5 1.10.5 with CMake correctly on different platforms (Centos, Ubuntu). We had to install with ./configure for the HDF5 installation to work on both platforms.

The HDF5 CMake information wasn’t clear at the time, but I may need to look into it again. Especially with the updated targets with newer versions of CMake.

Hi @blowekamp ,

I checked out ITKv5.2rc1, and using SimpleITK v2.0.2 but unfortunately I still get the CMake Threads::Threads error when generating.

A second issue that requires manual intervention in the build process. At the end of the SimpleITK build I get these errors:

/sandbox/sitkITKrc2/Code/BasicFilters/include/SimpleITKBasicFiltersGeneratedHeaders.i:51: Error: Unable to find 'sitkCoherenceEnhancingDiffusionImageFilter.h'
/sandbox/sitkITKrc2/Code/BasicFilters/include/SimpleITKBasicFiltersGeneratedHeaders.i:152: Error: Unable to find 'sitkLabelSetDilateImageFilter.h'
/sandbox/sitkITKrc2/Code/BasicFilters/include/SimpleITKBasicFiltersGeneratedHeaders.i:153: Error: Unable to find 'sitkLabelSetErodeImageFilter.h'
make[2]: *** [Wrapping/Tcl/CMakeFiles/SimpleITKTclsh.dir/build.make:425: Wrapping/Tcl/SimpleITKTCL_wrap.cxx] Error 1
make[1]: *** [CMakeFiles/Makefile2:1948: Wrapping/Tcl/CMakeFiles/SimpleITKTclsh.dir/all] Error 2
make: *** [Makefile:171: all] Error 2

For some reason the generated headers required for the SimpleITK build includes the following.

In file:  SimpleITK-build/Code/BasicFilters/include/SimpleITKBasicFiltersGeneratedHeaders.i

%include "sitkCoherenceEnhancingDiffusionImageFilter.h"
%include "sitkLabelSetDilateImageFilter.h"
%include "sitkLabelSetErodeImageFilter.h"

From my understanding these headers are generated from the ITK Modules Module_AnisotropicDiffusionLBR and Module_LabelErodeDilate which are not turned ON by default in the SuperBuild. So I didn’t enable it when building a non-SuperBuild ITK.

These are the modules I enabled in ITK:

Module_SimpleITKFilters       ON
Module_ITKIOTransformMINC     ON
Module_ITKReview              ON

When I compare against the SuperBuild’s SimpleITK-build directroy those headers are not included in the SimpleITKBasicFiltersGeneratedHeaders.i.

So, I just deleted the %include lines in SimpleITKBasicFiltersGeneratedHeaders.i and the non-SuperBuild ran to completion. Allowing me to use the libraries in my app.