# Library's CMake generates DLL. Application's CMake wants LIB

**URL:** https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408
**Category:** Usage
**Tags:** os:windows
**Created:** [December 18, 2019, 10:59am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408 "2019-12-18T10:59:06Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [December 18, 2019, 10:59am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/1 "2019-12-18T10:59:06Z")

</div>

My library has minimal, straightforward CMake code with the pertinent lines

```
add_library(MyLib <sources>)

install(
    TARGETS MyLib
    LIBRARY DESTINATION ${destination}/lib
    RUNTIME DESTINATION ${destination}/lib
    COMPONENT Libraries)
install(
    FILES mylib.h
    DESTINATION ${destination}/include
    COMPONENT Headers)

```

When executed under Windows, the system installs a `.DLL` file.

My application has minimal, straightforward CMake code to search for my library:

```
find_path(MyLib_INCLUDE_DIR mylib.h)
find_library(MyLib_LIBRARIES NAMES MyLib)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(MyLib DEFAULT_MSG MyLib_LIBRARIES MyLib_INCLUDE_DIR)

```

Which works under Linux, but under Windows results in

```
-- Could NOT find MyLib (missing: MyLib_LIBRARIES)

```

From experimentation I know that this error occurs whenever there is only a `.DLL` file, and no associated `.LIB` import library.

Shall I correct MyLib to create a `.LIB`, or is it possible to modify my application so that it is satisfied with a `.DLL` only? And how?

((cross-posting: [https://stackoverflow.com/questions/59390335](https://stackoverflow.com/questions/59390335)))

---

<div class="post-metadata">

### Author: ![fenrir](https://discourse.cmake.org/user_avatar/discourse.cmake.org/fenrir/32/734_2.png) [@fenrir](https://discourse.cmake.org/u/fenrir)
#### Post date: [December 18, 2019, 11:09am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/2 "2019-12-18T11:09:21Z")

</div>

Probably an even better solution would be for MyLib to produce the appropriate config files.  
In any case: in typical scenario on windows you need \*.lib for linking and \*.dll for running.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [December 18, 2019, 11:10am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/3 "2019-12-18T11:10:56Z")

</div>

In the meantime I found out that a .LIB file is generated, but not installed. I edited the question to show the `install` statements. So my question boils down to: How to install the .LIB file?

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [December 18, 2019, 11:18am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/4 "2019-12-18T11:18:35Z")

</div>

`.lib` files are installed as `ARCHIVE` targets, not as `LIBRARY` targets. So adding an `ARCHIVE DESTINATION ${destination}/lib` argument to your `install()` command should help.

---

<div class="post-metadata">

### Author: ![jwuttke](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/9dc877/32.png) [@jwuttke](https://discourse.cmake.org/u/jwuttke)
#### Post date: [December 18, 2019, 11:30am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/5 "2019-12-18T11:30:41Z")

</div>

Great. Just works. Thank you, Petr. Would you like to post your answer at [https://stackoverflow.com/questions/59390335](https://stackoverflow.com/questions/59390335)? Otherwise I will do so.

---

<div class="post-metadata">

### Author: ![Angew](https://discourse.cmake.org/user_avatar/discourse.cmake.org/angew/32/229_2.png) [@Angew](https://discourse.cmake.org/u/Angew)
#### Post date: [December 18, 2019, 11:33am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/6 "2019-12-18T11:33:01Z")

</div>

Feel free to post it to SO yourself. See [my SO profile](https://stackoverflow.com/users/1782465/reinstate-monica?tab=profile) for why I don’t (currently) want to post it myself.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [December 19, 2019, 1:01am UTC](https://discourse.cmake.org/t/librarys-cmake-generates-dll-applications-cmake-wants-lib/408/7 "2019-12-19T01:01:14Z")

</div>

You’ve already worked out the underlying issue you were facing, but in case it is of interest, you can see this and other related material covered in my CppCon 2019 talk:

> **[CppCon 2019: Deep CMake For Library Authors - Crascit](https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/)**
>
> This talk highlights key CMake features relevant to C++ cross-platform library authors, digging deeper into platform-specific quirks and conventions.
