# Building a library which depends on VTK: Headers not found.

**URL:** https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298
**Category:** Support
**Created:** [July 7, 2019, 9:14am UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298 "2019-07-07T09:14:28Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![sudomakeinstall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sudomakeinstall](https://discourse.vtk.org/u/sudomakeinstall)
#### Post date: [July 7, 2019, 9:14am UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/1 "2019-07-07T09:14:28Z")

</div>

All–

I’m trying to build a library which depends upon VTK, but am having trouble getting it to find the header files. I’ve put together a minimal example to show the error:

```
$ make
Scanning dependencies of target dv-utils-lib
[50%] Building CXX object CMakeFiles/dv-utils-lib.dir/src/dvTest.cxx.o
In file included from /Users/davisvigneault/Desktop/src/src/dvTest.cxx:1:
/Users/davisvigneault/Desktop/src/includes/dvTest.h:4:10: fatal error: 'vtkMatrix4x4.h' file not found
#include <vtkMatrix4x4.h>
         ^ ~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [CMakeFiles/dv-utils-lib.dir/src/dvTest.cxx.o] Error 1
make[1]: *** [CMakeFiles/dv-utils-lib.dir/all] Error 2
make: *** [all] Error 2

```

Here’s `CMakeLists.txt`:

```
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)
project(dv-commandline-utils)
find_package(VTK REQUIRED)
include_directories("includes/")
file(GLOB SRC src/*.cxx)
add_library(dv-utils-lib ${SRC})

```

Here’s `includes/dvTest.h`

```
#ifndef dv_Test_h
#define dv_Test_h

#include <vtkMatrix4x4.h>

double GetFirstElement(vtkMatrix4x4 *mat);

#endif

```

Here’s `src/dvTest.cxx`:

```
#include <dvTest.h>
#include <vtkMatrix4x4.h>

double GetFirstElement(vtkMatrix4x4 mat*) {
  return mat->GetElement(0,0);
}

```

I’m on Mac 10.14.5, on the master branch of VTK. Apologies if I’m missing something simple, and thanks in advance for any help!

Best, and thanks,

–Davis

---

<div class="post-metadata">

### Author: ![Ron84](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ron84/32/630_2.png) [@Ron84](https://discourse.vtk.org/u/Ron84)
#### Post date: [July 7, 2019, 10:49am UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/2 "2019-07-07T10:49:05Z")

</div>

The common pattern for VTK and any other package is this:

```auto
find_package(VTK REQUIRED #[[COMPONENTS vtkFiltersSources vtkIOLegacy ... NO_MODULE]])

if(VTK_FOUND)
    include(${VTK_USE_FILE}) # this is important

    add_library(${PROJECT_NAME} #[[...]])
    target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})
endif()

```

---

<div class="post-metadata">

### Author: ![sudomakeinstall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sudomakeinstall](https://discourse.vtk.org/u/sudomakeinstall)
#### Post date: [July 7, 2019, 5:49pm UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/3 "2019-07-07T17:49:05Z")

</div>

Ron–

Thanks for your response. I had previously been using `include(${VTK_USE_FILE})`, but upon updating to the master branch I began getting an error about there being an incorrect number of arguments to the include function. Is `${VTK_USE_FILE}` no longer being set? I gather from Dr. Lorensen’s examples on github [1] that this functionality has somehow been replaced by `vtk_module_autoinit` in recent versions of VTK.

Ultimately, I was able to get it all working (building a library that depends on VTK, and then building an executable which depends both on VTK and on my library) with something similar to this:

```
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(dv-commandline-utils)

find_package(VTK REQUIRED)

include_directories("includes/")
file(GLOB SRC src/*.cxx)
add_library(dv-utils-lib ${SRC})
target_link_libraries(dv-utils-lib ${VTK_LIBRARIES})

add_executable(dv-visualize-meshes dv-visualize-meshes.cxx)
target_link_libraries(dv-visualize-meshes ${VTK_LIBRARIES} dv-utils-lib)

vtk_module_autoinit(
  TARGETS dv-visualize-meshes
  MODULES ${VTK_LIBRARIES}
  )

```

Thanks very much for your help,

–Davis

---

<div class="post-metadata">

### Author: ![Ron84](https://discourse.vtk.org/user_avatar/discourse.vtk.org/ron84/32/630_2.png) [@Ron84](https://discourse.vtk.org/u/Ron84)
#### Post date: [July 7, 2019, 8:35pm UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/4 "2019-07-07T20:35:40Z")

</div>

My mistake. But this is the old problem with VTK. Nothing is well documented…

---

<div class="post-metadata">

### Author: ![sudomakeinstall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sudomakeinstall](https://discourse.vtk.org/u/sudomakeinstall)
#### Post date: [July 7, 2019, 8:41pm UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/5 "2019-07-07T20:41:33Z")

</div>

Ron–

No worries–your response nonetheless pointed me down the right path. At least what the ITK/VTK echosystem occasionally lacks in documentation, it makes up for with an active and supportive community!

Best, and thanks again,

–Davis

---

<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: [July 8, 2019, 4:05am UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/6 "2019-07-08T04:05:58Z")

</div>

Since you are using the VTK Master, try using: `Utilities/Maintenance/FindNeededModules.py`.  
This will produce an output something like this that only lists the modules needed by your library:

```auto
find_package(VTK
 COMPONENTS
    CommonColor
    CommonCore
    CommonDataModel
    CommonTransforms
    FiltersGeneral
    FiltersModeling
    FiltersSources
    IOGeometry
    IOLegacy
    IOPLY
    IOXML
    RenderingCore
    # These modules are suggested since they implement an existing module.
    # Uncomment those you need.
    # InteractionStyle # implements VTK::RenderingCore
    # RenderingFreeType # implements VTK::RenderingCore
    # RenderingOpenGL2 # implements VTK::RenderingCore
)

```

that you can drop into your CMake file.

Then …  
**Note:** _I haven’t tried this!_.

```auto
  add_library(dv-utils-lib MACOSX_BUNDLE ${SRC} )
  target_link_libraries(dv-utils-lib PRIVATE ${VTK_LIBRARIES})
  # vtk_module_autoinit is needed
  vtk_module_autoinit(
    TARGETS dv-utils-lib
    MODULES ${VTK_LIBRARIES}
    )

```

---

<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: [July 8, 2019, 10:42am UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/7 "2019-07-08T10:42:35Z")

</div>

> [@Ron84](#):
>
> But this is the old problem with VTK. Nothing is well documented…

ParaView is in its release cycle and has gotten documentation love. VTK will get the same before the release happens. There’s developer-level documentation, but user-level docs are missing right now.

---

<div class="post-metadata">

### Author: ![sudomakeinstall](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/58956e/32.png) [@sudomakeinstall](https://discourse.vtk.org/u/sudomakeinstall)
#### Post date: [July 10, 2019, 3:28pm UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/8 "2019-07-10T15:28:55Z")

</div>

Hey @amaclean very cool script! I’ve never known the right way to go about figuring out which components are needed.

I tried running it on my project, and it gave me the following:

```
find_package(VTK
 COMPONENTS
    CommonCore
    CommonDataModel
    CommonMath
    CommonTransforms
    FiltersCore
    FiltersExtraction
    FiltersGeneral
    FiltersModeling
    FiltersSources
    IOGeometry
    IOImage
    IOLegacy
    ImagingColor
    InteractionImage
    InteractionWidgets
    RenderingAnnotation
    RenderingCore
    RenderingOpenGL2
    RenderingVolumeOpenGL2
    # These modules are suggested since they implement an existing module.
    # Uncomment those you need.
    # InteractionStyle # implements VTK::RenderingCore
    # RenderingFreeType # implements VTK::RenderingCore
    # RenderingGL2PSOpenGL2 # implements VTK::RenderingOpenGL2
)

```

Looks good, but now it unfortunately can’t find my Qt headers. I expect that it’s related to the rendering core (see commented at the bottom of the script), but I’ve tried uncommenting each in turn, with no luck. Is there something special I need to do to get this working with Qt?

And again, thanks so much for your help.

Best,

–Davis

---

<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: [July 10, 2019, 11:23pm UTC](https://discourse.vtk.org/t/building-a-library-which-depends-on-vtk-headers-not-found/1298/9 "2019-07-10T23:23:09Z")

</div>

You will have to manually add other components. Tthe script only looks for vtk includes that start with lower-case vtk e.g. `vtkSmartPointer.h`
