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

**URL:** https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018
**Category:** Beginner Questions
**Created:** [April 30, 2020, 1:09pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018 "2020-04-30T13:09:03Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![hubutui](https://discourse.itk.org/user_avatar/discourse.itk.org/hubutui/32/716_2.png) [@hubutui](https://discourse.itk.org/u/hubutui)
#### Post date: [April 30, 2020, 1:09pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/1 "2020-04-30T13:09:04Z")

</div>

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

```auto
// 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`：

```auto
# 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:

```auto
-- 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](https://github.com/msys2/MINGW-packages/blob/master/mingw-w64-itk/PKGBUILD).

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 30, 2020, 1:53pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/2 "2020-04-30T13:53:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 30, 2020, 1:56pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/3 "2020-04-30T13:56:13Z")

</div>

> ```
> -DITK_USE_SYSTEM_HDF5=ON
> 
> ```

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

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.itk.org/user_avatar/discourse.itk.org/hubutui/32/716_2.png) [@hubutui](https://discourse.itk.org/u/hubutui)
#### Post date: [April 30, 2020, 2:01pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/4 "2020-04-30T14:01:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 30, 2020, 2:06pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/5 "2020-04-30T14:06:18Z")

</div>

> [@hubutui](#):
>
> 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.

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.itk.org/user_avatar/discourse.itk.org/hubutui/32/716_2.png) [@hubutui](https://discourse.itk.org/u/hubutui)
#### Post date: [April 30, 2020, 2:24pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/6 "2020-04-30T14:24:24Z")

</div>

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

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [April 30, 2020, 3:09pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/7 "2020-04-30T15:09:48Z")

</div>

Yes, with that system, the build will be very fast 🏍

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.itk.org/user_avatar/discourse.itk.org/hubutui/32/716_2.png) [@hubutui](https://discourse.itk.org/u/hubutui)
#### Post date: [April 30, 2020, 4:14pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/8 "2020-04-30T16:14:10Z")

</div>

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:

```auto
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.

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 1, 2020, 1:50am UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/9 "2020-05-01T01:50:44Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.itk.org/user_avatar/discourse.itk.org/hubutui/32/716_2.png) [@hubutui](https://discourse.itk.org/u/hubutui)
#### Post date: [May 1, 2020, 3:33am UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/10 "2020-05-01T03:33:13Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [May 5, 2020, 2:39pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/11 "2020-05-05T14:39:48Z")

</div>

> [@hubutui](#):
>
> So you mean if I build `itk` with `ITK_USE_SYSTEM_HDF5=OFF` , then `itk` will build `hdf5` and statically link to it.

Yes.

The steps, essentially:

```auto
# 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`.

---

<div class="post-metadata">

### Author: ![hubutui](https://discourse.itk.org/user_avatar/discourse.itk.org/hubutui/32/716_2.png) [@hubutui](https://discourse.itk.org/u/hubutui)
#### Post date: [May 6, 2020, 1:11am UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/12 "2020-05-06T01:11:13Z")

</div>

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

---

<div class="post-metadata">

### Author: ![wulicheng](https://discourse.itk.org/user_avatar/discourse.itk.org/wulicheng/32/1390_2.png) [@wulicheng](https://discourse.itk.org/u/wulicheng)
#### Post date: [May 6, 2020, 11:53pm UTC](https://discourse.itk.org/t/target-links-to-target-hdf5-hdf5-shared-but-the-target-was-not-found/3018/13 "2020-05-06T23:53:24Z")

</div>

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