# Add an existing library to a VTK module

**URL:** https://discourse.vtk.org/t/add-an-existing-library-to-a-vtk-module/2008
**Category:** Development
**Created:** [October 30, 2019, 5:17pm UTC](https://discourse.vtk.org/t/add-an-existing-library-to-a-vtk-module/2008 "2019-10-30T17:17:54Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![cobo](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cobo](https://discourse.vtk.org/u/cobo)
#### Post date: [October 30, 2019, 5:17pm UTC](https://discourse.vtk.org/t/add-an-existing-library-to-a-vtk-module/2008/1 "2019-10-30T17:17:55Z")

</div>

In a project I am generating a VTK module with vtk\_module\_add\_module(), to be built from a number of source files, and also to be linked with other modules with vtk\_module\_link(): one other self-built module, plus some Qt5 components (Qt5::Widgets etc.). So far so good.

But then I also need to link in a library of which I have just a header (_.h) and library (_.lib) file (yes, this is just for Windows).

If I try to achieve this using target\_link\_directories() and target\_link\_libraries(), I get an error message from both: “…can not be used on ALIAS target”.

Well, nice - I would need to call these with the “real” targets - but which are these? I am using a name with some prefix, like NNN::xyz.

So how do I get the “real name” for which NNN::xyz is only an alias?

Or else: Is there another way to add this lib file to the module? The code is actually used internally only, so any interface to other modules goes through my own functions.

---

<div class="post-metadata">

### Author: ![cobo](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/c/f17d59/32.png) [@cobo](https://discourse.vtk.org/u/cobo)
#### Post date: [October 30, 2019, 5:38pm UTC](https://discourse.vtk.org/t/add-an-existing-library-to-a-vtk-module/2008/2 "2019-10-30T17:38:59Z")

</div>

Just found a solution that at least cmake accepts:

```
if(MSVC)
  add_library(ext_lib STATIC IMPORTED)
  if(CMAKE_BUILD_TYPE STREQUAL "Debug")
    set_property(TARGET ext_lib PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/lib/extD.lib)
  else()
    set_property(TARGET ext_lib PROPERTY IMPORTED_LOCATION ${CMAKE_CURRENT_LIST_DIR}/lib/ext.lib)
  endif()
  vtk_module_link(NNN::xyz
    PRIVATE
	  ext_lib)
endif()

```

Let’s see if it finally works!

---

<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: [October 30, 2019, 6:20pm UTC](https://discourse.vtk.org/t/add-an-existing-library-to-a-vtk-module/2008/3 "2019-10-30T18:20:48Z")

</div>

That looks like what I’d suggest 🙂 . You’ll need `_vtk_module_install(ext_lib)` there as well so that it gets added to the export set.

You can also do `IMPORTED_LOCATION` and `IMPORTED_LOCATION_DEBUG` instead of the `if/else`. An `INTERFACE_INCLUDE_DIRECTORIES` would also save you a `vtk_module_include` call.
