# How to include vtk dll in my self projection?

**URL:** https://discourse.vtk.org/t/how-to-include-vtk-dll-in-my-self-projection/6985
**Category:** Support
**Created:** [October 27, 2021, 9:39am UTC](https://discourse.vtk.org/t/how-to-include-vtk-dll-in-my-self-projection/6985 "2021-10-27T09:39:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [October 27, 2021, 9:39am UTC](https://discourse.vtk.org/t/how-to-include-vtk-dll-in-my-self-projection/6985/1 "2021-10-27T09:39:58Z")

</div>

I want to use vtk in my team projection. I firstly install vtk, and collect the necessary dll, and the fold is:

```auto

Thirdparty
    VTK
        bin
            Debug
                xxx.dll
                ...
            Release
                xxx.dll
                ...
        include
                xxx
                ...
        lib
            Debug
                xxx
                ...
            Release
                ...

```

In my CMakeLists.txt:

```auto
set(VTI_DIR "xxx/Thirdparty/VTK")
include_directories(
    ${VTK_DIR}/include
)
target_link_libraries(Pro
    vtkCommonCore-9.0
    ....
)

```

For VTK 8, the CMakeLists.txt is OK, but it cause bug for vtk 9.0.  
The `target_link_libraries(Pro vtkCommonCore-9.0 ....)` is OK for release, but it is wrong for debug. Because, the dll is `vtkCommonCore-9.0d` for debug. The dll of debug has a more `d` than that of release.  
If I use `target_link_libraries(Pro vtkCommonCore-9.0d ....)` , the code would be ok for debug but wrong for release.

Can I remove the `d` in the dll of debug?

How can I fix this problem? Any suggestion is appreciated~~~

---

<div class="post-metadata">

### Author: ![codeling](https://discourse.vtk.org/user_avatar/discourse.vtk.org/codeling/32/3792_2.png) [@codeling](https://discourse.vtk.org/u/codeling)
#### Post date: [October 28, 2021, 8:24am UTC](https://discourse.vtk.org/t/how-to-include-vtk-dll-in-my-self-projection/6985/2 "2021-10-28T08:24:51Z")

</div>

As far as I know, the way to do this “properly” is to not use “vtkCommonCore-9.0” as library name in CMake directly, instead, use:

```auto
find_package(VTK)
if (VTK_VERSION VERSION_LESS "8.90.0")
  include(${VTK_USE_FILE})
  target_link_libraries(Pro ${VTK_LIBRARIES})
else()
  target_link_libraries(Pro ${VTK_LIBRARIES})
  vtk_module_autoinit(
    TARGETS Pro
    MODULES ${VTK_LIBRARIES}
    )
endif()

```

For more info I would recommend checking the VTK examples, especially the [Tutorial](https://kitware.github.io/vtk-examples/site/Cxx/Tutorial/Tutorial_Step1/)

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [October 28, 2021, 8:47am UTC](https://discourse.vtk.org/t/how-to-include-vtk-dll-in-my-self-projection/6985/3 "2021-10-28T08:47:02Z")

</div>

`find_package(VTK)` is very convenient if I have compiled VTK from source code in my computer.

However, if I don’t want to compile VTK in my computer, I only want to use VTK by dll/lib/include. How can I do?  
I have find one solution after reading the explanation of [cmake](https://cmake.org/cmake/help/latest/command/target_link_libraries.html).

```auto
target_link_libraries(Pro
    debug vtkCommonCore-9.0d
    optimized vtkCommonCore-9.0
    ....
)

```

The keyword of `debug` and `optimized` can distinguish debug/release.

But the above solution seem to be inconvenient.

[cmake](https://cmake.org/cmake/help/latest/command/target_link_libraries.html) provides another two methods:

1. A plain library name  
I use it as: `target_link_libraries(Pro -lvtkCommonCore)`, but it failed.

2. A generator expression.  
I use it as `target_link_libraries(Pro vtkCommonCore-9.0$<1:d;2:"">)`, but it also failed.

---

<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: [November 15, 2021, 9:05pm UTC](https://discourse.vtk.org/t/how-to-include-vtk-dll-in-my-self-projection/6985/4 "2021-11-15T21:05:24Z")

</div>

You should use `VTK::CommonCore`. That is a CMake target which will end up linking to the right thing for you.
