# Library "not found" after building test with CMake on Ubuntu.

**URL:** https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988
**Category:** Support
**Created:** [April 8, 2020, 7:19pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988 "2020-04-08T19:19:40Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 8, 2020, 7:19pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/1 "2020-04-08T19:19:40Z")

</div>

I built VTK from source (8.2.0) and I am using CMake 3.13.  
My system is Ubuntu 19.10, with kernel 5.3.0-42-generic.

I copied the [sphere example](https://lorensen.github.io/VTKExamples/site/Cxx/GeometricObjects/Sphere/) into a directory.

I did _not_ use the CMakeLists.txt file in the example, but I did use it as a guide for what I wrote:  
cmake\_minimum\_required(VERSION 3.12)  
project(“Display Sphere Example”)

```
set(VTK_DIR /home/me/opt/vtk/lib/cmake/vtk-8.2)
find_package(VTK REQUIRED)

add_executable(test
  test.cpp)

target_link_libraries(test
  PRIVATE
  ${VTK_LIBRARIES})

```

Afterwards, the executable built without error, but when running it, it appears that there are _some_ VTK libraries that are _not_ found (and confusingly, some _are_ found)? Running “readelf -d” on the resulting executable gives the correct RUNPATH:  
(RUNPATH) Library runpath: [/home/me/opt/vtk/lib]  
The RPATH is not set … and LD\_LIBRARY\_PATH does not contain “/home/me/opt/vtk/lib” (and I would rather not set LD\_LIBRARY\_PATH - although I will if I have to).

Running ldd on the resulting executable gives:  
…  
libvtkFiltersSources-8.2.so.1 =\> correct full path to library  
…  
libvtkFiltersGeometry-8.2.so.1 =\> not found

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 8, 2020, 7:54pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/2 "2020-04-08T19:54:19Z")

</div>

`DT_RUNPATH` is the replacement for `DT_RPATH`, so not having an RPATH is fine. However, it is odd that you have some VTK libraries and not others. Does `${VTK_LIBRARIES}` look sensible to you when you build the example?

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 8, 2020, 8:01pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/3 "2020-04-08T20:01:16Z")

</div>

Hi Ben - VTK\_LIBRARIES did indeed look sane, but what I was missing was:  
`include(${VTK_USE_FILE})`

It has been a few years since I have used VTK, and things seem to have evolved somewhat in my absence …

Thanks for looking at my question.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 8, 2020, 9:20pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/4 "2020-04-08T21:20:13Z")

</div>

Ah, yes, that would do it. In any case, `VTK_USE_FILE` is no longer needed in 9.0. I’ve grown foggy on remembering all the details of the 8.2 (and older) build system, sorry.

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 9, 2020, 2:59am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/5 "2020-04-09T02:59:39Z")

</div>

So - I should just get 9 … I’ll download it now.

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 9, 2020, 4:50am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/6 "2020-04-09T04:50:30Z")

</div>

Ok - downloaded 9.0.0, now the CMakeLists.txt file is:

```
cmake_minimum_required(VERSION 3.12)
project("Example")
set(VTK_DIR /home/me/opt/vtk/lib/cmake/vtk-9.0)
find_package(VTK REQUIRED)

add_executable(test test.cpp)
target_link_libraries(test ${VTK_LIBRARIES})
vtk_module_autoinit(TARGETS test
  MODULES ${VTK_LIBRARIES})

```

The executable builds fine, but only seems to be able to find all of the libraries when `LD_LIBRARY_PATH` is set (which I would prefer to not do). Apparently when it “worked” above, I was still in the shell that I had set `LD_LIBRARY_PATH` in.

`ldd` and `readelf` show similar results to the first time around.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 9, 2020, 5:07pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/7 "2020-04-09T17:07:40Z")

</div>

CMake should be adding RPATH entries in your build tree automatically. You may need to add paths for your install tree manually.

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 9, 2020, 10:50pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/8 "2020-04-09T22:50:08Z")

</div>

I think that CMake is setting `RUNPATH` correctly (my understanding is that `RUNPATH` has superseded `RPATH`). This is a part of what `readelf -d` returns for the executable … by now, I am starting to get the feeling that this really isn’t VTK’s fault at all, but I figured that there were plenty of other VTK users on Ubuntu who might know the answer …

```
[me@laptop build]$readelf -d test 

Dynamic section at offset 0x4b50 contains 42 entries:
  Tag Type Name/Value
 0x0000000000000001 (NEEDED) Shared library: [libvtkInteractionStyle-9.0.so.1]
... stuff ...
 0x0000000000000001 (NEEDED) Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED) Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED) Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH) Library runpath: [/home/me/opt/vtk/lib]
... morestuff ...
```

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 10, 2020, 1:59am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/9 "2020-04-10T01:59:45Z")

</div>

I think I have an idea about what the reason might be. I found it on [one of Qt’s pages](https://www.qt.io/blog/2011/10/28/rpath-and-runpath). The libraries that are indirectly loaded from the directly loaded libraries don’t have the `RUNPATH` set, so they can’t find the indirectly loaded libraries since they are in a nonstandard location.

I could stick the `RUNPATH` in there with `patchelf`, but apparently `chrpath` won’t do the job. I’m stuck using `LD_LIBRARY_PATH` until I can figure out a way to get CMake to put it in there for me.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 10, 2020, 12:40pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/10 "2020-04-10T12:40:48Z")

</div>

`RUNPATH` is not inherited across the loaded library chain, so each library in a non-standard place would need the `-rpath` flag for `$ORIGIN`. You’ll have to update the builds of those projects to set the proper flags.

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [April 10, 2020, 1:08pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/11 "2020-04-10T13:08:10Z")

</div>

What was confusing to me was that OpenCV builds with CMake and I don’t have this problem (it embeds the right RUNPATH in the resulting libraries), but VTK doesn’t for some reason.

There is a [CMake wiki](https://gitlab.kitware.com/cmake/community/-/wikis/doc/cmake/RPATH-handling) that talks about RPATH and sort of mentions the problem that I was having. I thought that it would have been as simple as supplying `-DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE`.

I guess that I will have to compare the two project `CMakeLists.txt` files to see if I can spot the difference.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [April 10, 2020, 1:10pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/12 "2020-04-10T13:10:26Z")

</div>

OpenCV might be setting some settings apart from default CMake settings like that. But `CMAKE_INSTALL_RPATH_USE_LINK_PATH` could certainly help here.

---

<div class="post-metadata">

### Author: ![ferdymercury](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ferdymercury/32/3870_2.png) [@ferdymercury](https://discourse.vtk.org/u/ferdymercury)
#### Post date: [September 30, 2020, 4:38pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/13 "2020-09-30T16:38:16Z")

</div>

I had the same issue today and this is the solution I found. I need to specify both commands for it to work in a non-default install directory:

`cmake -DCMAKE_INSTALL_PREFIX=/opt/VTK -DCMAKE_INSTALL_RPATH=/opt/VTK/lib -DCMAKE_INSTALL_RPATH_USE_LINK_PATH=TRUE /opt/VTK-src`

Now I can include VTK and ldd finds all libraries!

---

<div class="post-metadata">

### Author: ![cousinitt](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cousinitt/32/2398_2.png) [@cousinitt](https://discourse.vtk.org/u/cousinitt)
#### Post date: [October 1, 2020, 3:04am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/14 "2020-10-01T03:04:42Z")

</div>

You are a hero! Thanks!

---

<div class="post-metadata">

### Author: ![PerceptMD](https://discourse.vtk.org/user_avatar/discourse.vtk.org/perceptmd/32/2466_2.png) [@PerceptMD](https://discourse.vtk.org/u/PerceptMD)
#### Post date: [October 13, 2020, 4:00pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/15 "2020-10-13T16:00:34Z")

</div>

Today I removed the apt package VTK7 from my Ubuntu20.04.  
Then I compiled VTK8.2 from source with default configuration created with ccmake. (Eg.: `CMAKE_INSTALL_PREFIX=/usr/local`)  
Now when I run my applications that are based on VTK I get errors like this:  
“error while loading shared libraries: libvtksys-8.2.so.1: cannot open shared object file: No such file or directory”  
`readelf -d ./myApplication` shows that I am using “RUNPATH”.  
I did not change the default path but still I have the same problems described here.  
Any tips on how to fix this? I have struggle to translate the solution to my problem.

---

<div class="post-metadata">

### Author: ![ferdymercury](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ferdymercury/32/3870_2.png) [@ferdymercury](https://discourse.vtk.org/u/ferdymercury)
#### Post date: [October 13, 2020, 5:03pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/16 "2020-10-13T17:03:50Z")

</div>

What is the result of:  
locate libvtk\*.so ?

and then:  
ls -l fileyoufound.so

Did you recompile your application after compiling VTK?

What is the output of  
ldd ./MyApplication

---

<div class="post-metadata">

### Author: ![PerceptMD](https://discourse.vtk.org/user_avatar/discourse.vtk.org/perceptmd/32/2466_2.png) [@PerceptMD](https://discourse.vtk.org/u/PerceptMD)
#### Post date: [October 13, 2020, 9:34pm UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/17 "2020-10-13T21:34:07Z")

</div>

```
:~$ locate libvtk*.so

```

returns nothing. Did not expect that…

```
:/usr/local/lib$ ls
[...]
libvtksys-8.2.so
libvtksys-8.2.so.1
libvtktheora-8.2.so
libvtktheora-8.2.so.1
libvtktiff-8.2.so
libvtktiff-8.2.so.1
libvtkverdict-8.2.so
libvtkverdict-8.2.so.1
libvtkViewsContext2D-8.2.so
libvtkViewsContext2D-8.2.so.1
libvtkViewsCore-8.2.so
libvtkViewsCore-8.2.so.1
libvtkViewsInfovis-8.2.so
libvtkViewsInfovis-8.2.so.1
libvtkzlib-8.2.so
libvtkzlib-8.2.so.1

```

And:

```
:/usr/local/lib$ ls -l fileyoufound.so
ls: Zugriff auf 'fileyoufound.so' nicht möglich: Datei oder Verzeichnis nicht gefunden
-> sth. like "Access not possible. File or directory not found"

```

My application uses library X and this has VTK as dependency. I recompiled both several times. Did not change anything. Already the compiled examples of library X fail at runtime with missing one of vtk’s .so files.

---

<div class="post-metadata">

### Author: ![ferdymercury](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ferdymercury/32/3870_2.png) [@ferdymercury](https://discourse.vtk.org/u/ferdymercury)
#### Post date: [October 14, 2020, 6:25am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/18 "2020-10-14T06:25:24Z")

</div>

Run ‘sudo updatedb’ before calling ‘locate’.

How do you compile your library? With make or cmake?

Do you specify -Wl,rpath=/usr/local/lib ?

What is the output of:  
ldd ./MyApplicaction

?

---

<div class="post-metadata">

### Author: ![PerceptMD](https://discourse.vtk.org/user_avatar/discourse.vtk.org/perceptmd/32/2466_2.png) [@PerceptMD](https://discourse.vtk.org/u/PerceptMD)
#### Post date: [October 14, 2020, 7:57am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/19 "2020-10-14T07:57:57Z")

</div>

Same result for “locate” after “sudo updatedb”.

VTK and library X using VTK are compiled with

```
mkdir build
cd build
ccmake ..
make -j
sudo make install

```

Yesterday I got:

```
ldd ./myApplication
libvtkfreetype-8.2.so.1 => not found
libvtkglew-8.2.so.1 => not found
libvtkCommonSystem-8.2.so.1 => not found
libvtksys-8.2.so.1 => not found
libvtkFiltersGeometry-8.2.so.1 => not found
libvtkCommonComputationalGeometry-8.2.so.1 => not found
libvtkCommonSystem-8.2.so.1 => not found
libvtkCommonMisc-8.2.so.1 => not found
libvtksys-8.2.so.1 => not found

```

Today libraries are found. I dont really know why…

```
$ ldd ./ground_truth_gen 
libvtkInteractionStyle-8.2.so.1 => /usr/local/lib/libvtkInteractionStyle-8.2.so.1 (0x00007f7e1a757000)
libvtkRenderingFreeType-8.2.so.1 => /usr/local/lib/libvtkRenderingFreeType-8.2.so.1 (0x00007f7e1a68b000)
libvtkRenderingOpenGL2-8.2.so.1 => /usr/local/lib/libvtkRenderingOpenGL2-8.2.so.1 (0x00007f7e1a2a1000)
libvtkRenderingCore-8.2.so.1 => /usr/local/lib/libvtkRenderingCore-8.2.so.1 (0x00007f7e19f0c000)
libvtkCommonDataModel-8.2.so.1 => /usr/local/lib/libvtkCommonDataModel-8.2.so.1 (0x00007f7e1989f000)
libvtkCommonMath-8.2.so.1 => /usr/local/lib/libvtkCommonMath-8.2.so.1 (0x00007f7e19873000)
libvtkCommonCore-8.2.so.1 => /usr/local/lib/libvtkCommonCore-8.2.so.1 (0x00007f7e18f2b000)

```

I dont know why it is suddenly running. I linked one of my several CMake tagets with `-Wl,--enable-new-dtags` which seemed to solve the problem. But this was no solution in my case as I also need the example tools build with library X. As these still failed, I deleted the extra flags in my CMakeList.txt.  
These example tools still fail. I will look at this again.

---

<div class="post-metadata">

### Author: ![ferdymercury](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ferdymercury/32/3870_2.png) [@ferdymercury](https://discourse.vtk.org/u/ferdymercury)
#### Post date: [October 14, 2020, 8:36am UTC](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988/20 "2020-10-14T08:36:58Z")

</div>

Try with:  
`locate libvtksys`  
without the \*

or  
`locate libvtk`

-Wl,rpath=… could also help when compiling maybe.

Otherwise, exporting LD\_LIBRARY\_PATH with your extra search path, too, to see if it runs well.

[Next page](https://discourse.vtk.org/t/library-not-found-after-building-test-with-cmake-on-ubuntu/2988.md?page=2)
