# Building ITK with BUILD\_SHARED\_LIBS flag ON

**URL:** <https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176>\
**Category:** Engineering\
**Created:** [August 20, 2019, 9:28am UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176 "2019-08-20T09:28:20Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)\
**Post date:** [August 20, 2019, 9:28am UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/1 "2019-08-20T09:28:20Z")

</div>

I’m trying to build ITK 5.0.1 on Ubuntu with BUILD\_SHARED\_LIBS flag ON.  
I successfully configure and generate. I create appropriate .so files in cmake\_install\_prefix directory.  
But when I try to simple HelloWorld project from examples, I get this error.

```auto
error while loading shared libraries: libitkdouble-conversion-5.0.so.1: cannot open shared object file: No such file or directory.

```

In contrast of dynamic libraries, I can build and test static libraries(with BUILD\_SHARED\_LIBS flag OFF).  
I think the problem is with linking.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [August 20, 2019, 1:57pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/2 "2019-08-20T13:57:40Z")

</div>

Is your compiled ITK’s `lib` directory in the [library load path](https://unix.stackexchange.com/questions/22926/where-do-executables-look-for-shared-objects-at-runtime)? You might need to “install” ITK for shared libraries to be found correctly. If that is not the case, please provide more details.

---

<div class="post-metadata">

**Author:** ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)\
**Post date:** [August 20, 2019, 2:04pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/3 "2019-08-20T14:04:02Z")

</div>

I have installed binaries in custom path, not in usr/local.  
I want to have built binaries, which can be used in other linux machines either(not only for mine).  
I have added only BUILD\_SHARED\_LIBS to ON in cmake gui. In contrast of this static libraries worked fine.

---

<div class="post-metadata">

**Author:** ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)\
**Post date:** [August 20, 2019, 2:25pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/4 "2019-08-20T14:25:17Z")

</div>

I have even tried to install shared libs in usr/local. Still cause the 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:** [August 20, 2019, 2:27pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/5 "2019-08-20T14:27:52Z")

</div>

As noted in [the link provided by @dzenanz](https://unix.stackexchange.com/questions/22926/where-do-executables-look-for-shared-objects-at-runtime), first confirm that `/usr/local/lib` is in `/etc/ld.so.conf`, and `ldconfig` must be execute to update the operating system cache of the libraries found in the configured directories.

---

<div class="post-metadata">

**Author:** ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)\
**Post date:** [August 20, 2019, 2:41pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/6 "2019-08-20T14:41:57Z")

</div>

I want to create binaries which can be used in different linuxes(Not only on in mine)

---

<div class="post-metadata">

**Author:** ![nm97](https://discourse.itk.org/user_avatar/discourse.itk.org/nm97/32/814_2.png) [@nm97](https://discourse.itk.org/u/nm97)\
**Post date:** [August 20, 2019, 3:18pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/7 "2019-08-20T15:18:23Z")

</div>

I think the problem is with rpath. How I can tell linker to find libraries in the `lib` directory?

---

<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:** [August 20, 2019, 5:04pm UTC](https://discourse.itk.org/t/building-itk-with-build-shared-libs-flag-on/2176/8 "2019-08-20T17:04:16Z")

</div>

If an ITK build tree is used (versus an install tree), CMake sets and retains the rpath so the libraries will be found where they are built. In this case, though, the build tree is fixed. For an install tree, the rpath is usually stripped.

There are many other options. One is to create a Linux distribution-specific package, and install into standard library location, e.g. `/usr/lib`.

Another option, if distributing an application, is the CTKAppLauncher:

> **[commontk/AppLauncher](https://github.com/commontk/AppLauncher)**
>
> Simple and small program allowing to set the environment of any executable. - commontk/AppLauncher
