Building ITK with BUILD_SHARED_LIBS flag ON

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.

error while loading shared libraries: 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.

Is your compiled ITK’s lib directory in the library load path? You might need to “install” ITK for shared libraries to be found correctly. If that is not the case, please provide more details.

1 Like

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.

I have even tried to install shared libs in usr/local. Still cause the same error

As noted in the link provided by @dzenanz, first confirm that /usr/local/lib is in /etc/, and ldconfig must be execute to update the operating system cache of the libraries found in the configured directories.

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

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

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: