# How to link with external library?

**URL:** https://discourse.paraview.org/t/how-to-link-with-external-library/17410
**Category:** Development
**Created:** [January 27, 2026, 11:05am UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410 "2026-01-27T11:05:15Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [January 27, 2026, 11:05am UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/1 "2026-01-27T11:05:15Z")

</div>

Hi,

I have a C++ ParaView plugin that does not use VTK (so no _vtk.module_ file). I want to link my plugin with the external library [spdlog](https://github.com/gabime/spdlog), which is contained as a Git submodule in my project. This library integrates well with the CMake commands

```cmake
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/external/spdlog)
target_link_libraries(mytarget PUBLIC spdlog::spdlog)

```

in a non ParaView project. However, I don’t know the corresponding VTK/ParaView wrapper commands. In my plugin, I use the following wrappers:

```cmake
paraview_plugin_find_plugins
paraview_plugin_scan
paraview_plugin_build
paraview_add_plugin

```

and I have a `paraview.plugin` file. I cannot use `vtk_module_link`, as my plugin does not use VTK modules.

Could you tell me how to expose the headers of _spdlog_ and link it with my ParaView plugin ?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [January 27, 2026, 3:21pm UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/2 "2026-01-27T15:21:29Z")

</div>

`target_link_libraries(plugintarget PRIVATE spdlog::spdlog)` should be fine. Plugins and VTK modules are CMake targets at heart (VTK and ParaView add additional properties on top that “make” them what they are).

---

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [January 27, 2026, 3:41pm UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/3 "2026-01-27T15:41:26Z")

</div>

At which level should I put `target_link_libraries`? After `paraview_add_plugin(plugintarget ...)`?  
And `target_include_directories` to let CMake recognize the include directory of the source of the library?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [January 28, 2026, 1:55am UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/4 "2026-01-28T01:55:22Z")

</div>

Yes, `paraview_add_plugin` makes the target, so it has to go after that. Ideally your package’s target would be enough and you wouldn’t need `target_include_directories`.

---

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [January 28, 2026, 10:03am UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/5 "2026-01-28T10:03:05Z")

</div>

Thanks, it works fine, no need for `target_include_directories`. However, I noticed that sometimes an explicit include directory command is necessary. I have another plugin, which wraps a VTK module, that links with my own library _mylib_. In that case, `vtk_module_link` is not sufficient, I still have to use `vtk_module_include`. Do you know why this is the case? Maybe the CMake export is properly written for _spdlog_, but not for _mylib_?

EDIT: I keep this paragraph because it may help others, but [the solution is here](https://github.com/gabime/spdlog/issues/3174#issuecomment-2340931508).  
Turning back to the original question about spdlog: during the build, `libspdlog.so` is put in the build directory, so my plugin works when launched from the build directory. However, the installation step does not copy `libspdlog.so` into the install directory. Instead of doing it manually (which works by the way), I tried

```auto
install(TARGETS spdlog DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})

```

but it still doesn’t copy. Do you know why?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.paraview.org/u/ben.boeckel)
#### Post date: [January 28, 2026, 7:14pm UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/6 "2026-01-28T19:14:23Z")

</div>

> [@CsatiZoltan](#):
>
> Thanks, it works fine, no need for `target_include_directories`. However, I noticed that sometimes an explicit include directory command is necessary. I have another plugin, which wraps a VTK module, that links with my own library _mylib_. In that case, `vtk_module_link` is not sufficient, I still have to use `vtk_module_include`. Do you know why this is the case? Maybe the CMake export is properly written for _spdlog_, but not for _mylib_?

Your target does not export its usage requirements properly. See [this guide](https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#exporting-targets).

> [@CsatiZoltan](#):
>
> Turning back to the original question about spdlog: during the build, `libspdlog.so` is put in the build directory, so my plugin works when launched from the build directory. However, the installation step does not copy `libspdlog.so` into the install directory. Instead of doing it manually (which works by the way), I tried
> 
> ```auto
> install(TARGETS spdlog DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR})
> 
> ```
> 
> but it still doesn’t copy. Do you know why?

You cannot install `IMPORTED` targets with `install(TARGETS)`. There is [`install(IMPORTED_RUNTIME_ARTIFACTS)`](https://cmake.org/cmake/help/latest/command/install.html#imported-runtime-artifacts) though.

---

<div class="post-metadata">

### Author: ![CsatiZoltan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/csatizoltan/32/6997_2.png) [@CsatiZoltan](https://discourse.paraview.org/u/CsatiZoltan)
#### Post date: [January 28, 2026, 7:28pm UTC](https://discourse.paraview.org/t/how-to-link-with-external-library/17410/7 "2026-01-28T19:28:18Z")

</div>

Perfect, thanks a lot.
