# VTK find\_package fails with includes

**URL:** https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671
**Category:** Support
**Created:** [April 30, 2021, 8:21am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671 "2021-04-30T08:21:49Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![nparent](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nparent/32/3305_2.png) [@nparent](https://discourse.vtk.org/u/nparent)
#### Post date: [April 30, 2021, 8:21am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/1 "2021-04-30T08:21:49Z")

</div>

Hi, I am facing an issue with the includes in my code.  
In my _CMakeLists.txt_ I first create a library, then an executable which include vtk headers.  
If I remove the add\_library (so far my executable does not depend on it), there is no issue, my executable is produced.  
Otherwise, running _make_ fails with first vtk header included “vtkActor.h” no such file… Weirdly, If i place my main.cpp aside my CMakeLists.txt no issue encountered.

So far, my fix has been to create the variable VTK\_INCLUDE\_DIRS and to get all vtk include directories.

Personally, I think it is a shame that the VTK\_INCLUDE\_DIRS is not filled automatically with the command find\_package …

Your comments are most welcome !

---

<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 30, 2021, 1:34pm UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/2 "2021-04-30T13:34:13Z")

</div>

`VTK_INCLUDE_DIRS` is no longer needed. Just link to the appropriate library and the include directories come in automatically. For `vtkActor.h`, you would want the `VTK::RenderingCore` library.

---

<div class="post-metadata">

### Author: ![nparent](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nparent/32/3305_2.png) [@nparent](https://discourse.vtk.org/u/nparent)
#### Post date: [April 30, 2021, 1:43pm UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/3 "2021-04-30T13:43:11Z")

</div>

I know, I have actually based my CMakeLists.txt on the one in the [example](https://kitware.github.io/vtk-examples/site/Cxx/GeometricObjects/PolyLine/).  
I have reproduced the bug within this example. Say I use add\_library(…) before add\_executable and the error with the includes arise. As I said I moved the main.cpp to src/apps because when it stays aside the CMakeLists.txt the issue disappears…

So this looks very much like a bug ?  
Here is my CMakeLists.txt[CMakeLists.txt](https://discourse.vtk.org/uploads/short-url/jRldPn8iEUVzDsFefMmJ55jjoZe.txt) (1.9 KB)

Anyway, I think, filling the VTK\_INCLUDE\_DIRS by the find\_package provides more freedom and is more custom …

---

<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 30, 2021, 2:31pm UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/4 "2021-04-30T14:31:24Z")

</div>

`VTK_INCLUDE_DIRS` is gone and I’m not bringing it back because it shouldn’t be needed. Its usage would just be papering over other problems. Can you post the actual error you’re getting?

---

<div class="post-metadata">

### Author: ![nparent](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nparent/32/3305_2.png) [@nparent](https://discourse.vtk.org/u/nparent)
#### Post date: [April 30, 2021, 2:43pm UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/5 "2021-04-30T14:43:07Z")

</div>

nparent@paradis:/scratch/nparent/Formations/vtk/MyExample/build$ make  
Scanning dependencies of target knitsim  
[25%] Building CXX object CMakeFiles/knitsim.dir/src/apps/main.cpp.o  
/scratch/nparent/Formations/vtk/MyExample/src/apps/main.cpp:1:10: fatal error: vtkActor.h: No such file or directory  
#include \<vtkActor.h\>  
^ ~~~~~~~~~~~  
compilation terminated.  
CMakeFiles/knitsim.dir/build.make:62: recipe for target ‘CMakeFiles/knitsim.dir/src/apps/main.cpp.o’ failed  
make[2]: \*\*\* [CMakeFiles/knitsim.dir/src/apps/main.cpp.o] Error 1  
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/knitsim.dir/all’ failed  
make[1]: \*\*\* [CMakeFiles/knitsim.dir/all] Error 2  
Makefile:83: recipe for target ‘all’ failed  
make: \*\*\* [all] Error 2

---

<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 30, 2021, 4:28pm UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/6 "2021-04-30T16:28:22Z")

</div>

Can out send `make VERBOSE=1` output to show the command line that gets generated?

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 1, 2021, 8:06am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/7 "2021-05-01T08:06:44Z")

</div>

Have you download the tar file in [PolyLine](https://kitware.github.io/vtk-examples/site/Cxx/GeometricObjects/PolyLine/) and built it? This should build with no issues. In the CMakeLists.txt file `include(${VTK_USE_FILE})` is only applicable to VTK versions less then 8.90.

Use `VTK_LIBRARIES` instead. You can check what libraries will be used by:

```auto
message(STATUS "VTK Libraries: ${VTK_LIBRARIES}")

```

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 3, 2021, 2:14am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/8 "2021-05-03T02:14:05Z")

</div>

I just had a look at your CmakeLists.txt file, in particular ` add_executable(Writer MACOSX_BUNDLE src/apps/main.cpp )`. I don’t know your directory layout but CMake expects absolute paths so you should be expressing the path to `main.cpp` relative to ${CMAKE\_CURRENT\_SOURCE\_DIR} , which is the directory containing the current CMakeLists.txt file e.g perhaps:

```auto
${CMAKE_CURRENT_SOURCE_DIR}/src/apps/main.cpp

```

With regard to directory layout and CMake files it may be worth looking at something like this: [Simple Modern CMake Tutorial Part 1](https://levelup.gitconnected.com/simple-modern-cmake-tutorial-b0c1c362cd2c) or [An Introduction to Modern CMake](https://cliutils.gitlab.io/modern-cmake/).

---

<div class="post-metadata">

### Author: ![nparent](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nparent/32/3305_2.png) [@nparent](https://discourse.vtk.org/u/nparent)
#### Post date: [May 3, 2021, 7:07am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/9 "2021-05-03T07:07:08Z")

</div>

> [@amaclean](#):
>
> `${CMAKE_CURRENT_SOURCE_DIR}`

Here it is :

nparent@paradis:/scratch/nparent/Formations/vtk/MyExample/build$ make VERBOSE=1  
/usr/bin/cmake -H/scratch/nparent/Formations/vtk/MyExample -B/scratch/nparent/Formations/vtk/MyExample/build --check-build-system CMakeFiles/Makefile.cmake 0  
/usr/bin/cmake -E cmake\_progress\_start /scratch/nparent/Formations/vtk/MyExample/build/CMakeFiles /scratch/nparent/Formations/vtk/MyExample/build/CMakeFiles/progress.marks  
make -f CMakeFiles/Makefile2 all  
make[1] : on entre dans le répertoire « /scratch/nparent/Formations/vtk/MyExample/build »  
make -f CMakeFiles/knitsim.dir/build.make CMakeFiles/knitsim.dir/depend  
make[2] : on entre dans le répertoire « /scratch/nparent/Formations/vtk/MyExample/build »  
cd /scratch/nparent/Formations/vtk/MyExample/build && /usr/bin/cmake -E cmake\_depends “Unix Makefiles” /scratch/nparent/Formations/vtk/MyExample /scratch/nparent/Formations/vtk/MyExample /scratch/nparent/Formations/vtk/MyExample/build /scratch/nparent/Formations/vtk/MyExample/build /scratch/nparent/Formations/vtk/MyExample/build/CMakeFiles/knitsim.dir/DependInfo.cmake --color=  
make[2] : on quitte le répertoire « /scratch/nparent/Formations/vtk/MyExample/build »  
make -f CMakeFiles/knitsim.dir/build.make CMakeFiles/knitsim.dir/build  
make[2] : on entre dans le répertoire « /scratch/nparent/Formations/vtk/MyExample/build »  
[25%] Building CXX object CMakeFiles/knitsim.dir/src/apps/main.cpp.o  
/usr/bin/c++ -DEIGEN\_DONT\_PARALLELIZE -DEIGEN\_YES\_I\_KNOW\_SPARSE\_MODULE\_IS\_NOT\_STABLE\_YET -Dknitsim\_EXPORTS -std=c++0x -fPIC -msse3 -Wno-unused -Wno-enum-compare -fPIC -o CMakeFiles/knitsim.dir/src/apps/main.cpp.o -c /scratch/nparent/Formations/vtk/MyExample/src/apps/main.cpp  
/scratch/nparent/Formations/vtk/MyExample/src/apps/main.cpp:1:10: fatal error: vtkActor.h: Aucun fichier ou dossier de ce type  
#include \<vtkActor.h\>  
^ ~~~~~~~~~~~  
compilation terminated.  
CMakeFiles/knitsim.dir/build.make:62: recipe for target ‘CMakeFiles/knitsim.dir/src/apps/main.cpp.o’ failed  
make[2]: \*\*\* [CMakeFiles/knitsim.dir/src/apps/main.cpp.o] Error 1  
make[2] : on quitte le répertoire « /scratch/nparent/Formations/vtk/MyExample/build »  
CMakeFiles/Makefile2:67: recipe for target ‘CMakeFiles/knitsim.dir/all’ failed  
make[1]: \*\*\* [CMakeFiles/knitsim.dir/all] Error 2  
make[1] : on quitte le répertoire « /scratch/nparent/Formations/vtk/MyExample/build »  
Makefile:83: recipe for target ‘all’ failed  
make: \*\*\* [all] Error 2

---

<div class="post-metadata">

### Author: ![nparent](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nparent/32/3305_2.png) [@nparent](https://discourse.vtk.org/u/nparent)
#### Post date: [May 3, 2021, 7:13am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/10 "2021-05-03T07:13:37Z")

</div>

Thanks for looking at it, but it worked with the relative path. But clearly a bad habit !

---

<div class="post-metadata">

### Author: ![nparent](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nparent/32/3305_2.png) [@nparent](https://discourse.vtk.org/u/nparent)
#### Post date: [May 3, 2021, 7:19am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/11 "2021-05-03T07:19:40Z")

</div>

So thanks a lot everybody for helping me out.

Week-end rest gave me the answer. It happens that in the add\_library I used a file( GLOB RECURSE …)  
which searches in the Apps folder. In this Apps folder, are the files with main function for which I want to produce an exectuable and they are then liked with the library.

So my fix, is to put this folder somewhere else so that those files are now sources of the library.

---

<div class="post-metadata">

### Author: ![amaclean](https://discourse.vtk.org/user_avatar/discourse.vtk.org/amaclean/32/224_2.png) [@amaclean](https://discourse.vtk.org/u/amaclean)
#### Post date: [May 3, 2021, 8:06am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/12 "2021-05-03T08:06:44Z")

</div>

Glad you solved it! The links I mentioned will help.

---

<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: [May 3, 2021, 10:55am UTC](https://discourse.vtk.org/t/vtk-find-package-fails-with-includes/5671/13 "2021-05-03T10:55:35Z")

</div>

> [@amaclean](#):
>
> I don’t know your directory layout but CMake expects absolute paths so you should be expressing the path to `main.cpp` relative to ${CMAKE\_CURRENT\_SOURCE\_DIR}

This is just false. CMake looks up source files relative to `${CMAKE_CURRENT_SOURCE_DIR}` when they are relative automatically.

It seems the issue was that there was a `file(GLOB_RECURSE)` laying around (IMO, a bad habit for listing source files), not anything with a path specification.
