Target links to target "hdf5::hdf5-shared" but the target was not found

Hi, I test helloword itk project on Windows 10, MSYS2, but failed. Here is my code:

// main.cpp
#include "itkImage.h"
#include "itkImageFileWriter.h"

int main(int argc, char *argv[]) {
        std::cout << "ITK Hello World !" << std::endl;

        return EXIT_SUCCESS;
}

and my CMakeLists.txt

# CMakeLists.txt
project (hello)
add_executable(hello)
find_package(ITK REQUIRED)
include(${ITK_USE_FILE})
target_sources(hello PRIVATE main.cpp)
target_include_directories(hello PRIVATE ${ITK_INCLUDE_DIRS})
target_link_libraries(hello ${ITK_LIBRARIES})

cmake -B build outputs:

-- Building for: Unix Makefiles
-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe
-- Check for working C compiler: C:/msys64/mingw64/bin/cc.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe
-- Check for working CXX compiler: C:/msys64/mingw64/bin/c++.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: C:/msys64/mingw64 (found version "4.2.0")
-- Configuring done
CMake Error at CMakeLists.txt:3 (add_executable):
  Target "hello" links to target "hdf5::hdf5-shared" 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 CMakeLists.txt:3 (add_executable):
  Target "hello" links to target "hdf5::hdf5_cpp-shared" 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 CMakeLists.txt:3 (add_executable):
  Target "hello" links to target "hdf5::hdf5-shared" 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 CMakeLists.txt:3 (add_executable):
  Target "hello" links to target "hdf5::hdf5_cpp-shared" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?


-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.

itk 5.0.1 build with this PKGBUILD.

Hi @hubutui,

Please try the ITK Git v5.1.0 tag, which has addressed MinGW-w64 MSYS issues (although I have not tested that PKGBUILD recipe).

Thanks,
Matt

-DITK_USE_SYSTEM_HDF5=ON

This may need to be OFF, but make sure to use v5.1.0.

OK, I’ll try to create itk 5.1.0 from the PKGBUILD recipe with ITK_USE_SYSTEM_HDF5=OFF. I’m not sure how long would it take to build it.

The build will be much faster with the Ninja generator. It should take < 10 minutes.

Wow, could this be done with AMD Ryzen R5 3550, 16G RAM? I can’t believe it.

Yes, with that system, the build will be very fast :motorcycle:

I have build itk 5.1.0 with ITK_USE_SYSTEM_HDF5=ON. And now this project could be built, but fail to run. Error log:

D:/Projects/hello/build-system-hdf5/hello.exe: error while loading shared libraries: ?: cannot open shared object file: No such file or directory

It did not show me which lib is missing.

I also try ITK_USE_SYSTEM_HDF5=OFF, there is a file conflict (/mingw64/lib/libhdf5.settings) with hdf5 from the system. I manual remove it from the final itk pkg to avoid file conflict. I could build this helloworld project, but could not run it, with same error.

The build a hello world without worrying about determining the dependent libraries and setting up the run time environment to find them, build ITK independently from the MSYS package with its default build configuration. It will build ITK and third party static libraries that get embedded into the executable.

So you mean if I build itk with ITK_USE_SYSTEM_HDF5=OFF, then itk will build hdf5 and statically link to it. Then maybe itk should not install /mingw64/lib/libhdf5.settings to the system, right?

Yes.

The steps, essentially:

# Open an MSYS shell
git clone https://github.com/InsightSoftwareConsortum/ITK
cd ITK
git checkout v5.1.0
cd ..
mkdir ITK-build
cd ITK-build
cmake -GNinja -DBUILD_TESTING=OFF ../ITK
ninja
cd ..
cd hello-world-build
cmake -DITK_DIR=$PWD/../ITK-build -GNinja ../hello-world
ninja

Then maybe itk should not install /mingw64/lib/libhdf5.settings to the system, right?

Yes, this should not be the case if ITK_USE_SYSTEM_HDF5 is OFF.

Hmm, but in fact, make install will install libhdf5.settings as /mingw64/lib/libhdf5.settings.

I think you should add #include<stdio.h>