# find\_library won't find DLLs

**URL:** https://discourse.cmake.org/t/find-library-wont-find-dlls/4050
**Category:** Code
**Tags:** os:windows, comp:msvc
**Created:** [September 8, 2021, 6:33am UTC](https://discourse.cmake.org/t/find-library-wont-find-dlls/4050 "2021-09-08T06:33:03Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![samw](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@samw](https://discourse.cmake.org/u/samw)
#### Post date: [September 8, 2021, 6:33am UTC](https://discourse.cmake.org/t/find-library-wont-find-dlls/4050/1 "2021-09-08T06:33:03Z")

</div>

I’m trying to write a FindGigeSim.cmake module that creates imported targets for a 3rd party library.

I’m having trouble getting it to work on Windows. Specifically, the following command fails to find the `gigesimsdk64.dll` file:

```auto
find_library(
    GigeSim_LIBRARY
    NAMES gigesimsdk64
    PATHS "C:/Program Files/GigESim/Bin"
          "/usr/lib/GigeSimSDK"
)

```

I found the command fails because the `CMAKE_FIND_LIBRARY_SUFFIXES` variable only contains `".lib"` and not `".dll"`.

I’ve read other posts (like [this one](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387)) which state this is by design, since on Windows, you link to the import-lib instead of the DLL directly.

However, _ **I still need the DLL path** _ to set the `IMPORTED_LOCATION` property on the imported target, correct? I suppose I could add a separate call to `find_path` that looks exclusively for the `.dll`; or I can temporarily add `.dll` to the `CMAKE_FIND_LIBRARY_SUFFIXES`, but I wonder if there is a more elegant way to solve this?

I would also like to point out the [documentation](https://cmake.org/cmake/help/latest/variable/CMAKE_FIND_LIBRARY_SUFFIXES.html) for `CMAKE_FIND_LIBRARY_SUFFIXES`:

> On Windows systems this is typically `.lib` and `.dll`

So part of my confusion is that the docs state that `.dll` should be present.

FWIW, I’m using Cmake 3.21.2 on Windows 10 with the Visual Studio 2019 generator. My minimum required version is set to 3.10.

Thanks in advance for your help!

---

<div class="post-metadata">

### Author: ![bill.hoffman](https://discourse.cmake.org/user_avatar/discourse.cmake.org/bill.hoffman/32/13_2.png) [@bill.hoffman](https://discourse.cmake.org/u/bill.hoffman)
#### Post date: [September 8, 2021, 9:09pm UTC](https://discourse.cmake.org/t/find-library-wont-find-dlls/4050/2 "2021-09-08T21:09:22Z")

</div>

Looks like the documentation is bad. I think you would have to use find\_file to find a .dll. As you can’t actually link to a .dll find\_library will not find it.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 9, 2021, 2:37am UTC](https://discourse.cmake.org/t/find-library-wont-find-dlls/4050/3 "2021-09-09T02:37:41Z")

</div>

Yes, `find_file` is what you probably need for the `.dll` file. The `.lib` should be set as the `IMPORTED_IMPLIB` property by the way.

---

<div class="post-metadata">

### Author: ![samw](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/9de053/32.png) [@samw](https://discourse.cmake.org/u/samw)
#### Post date: [September 9, 2021, 5:09am UTC](https://discourse.cmake.org/t/find-library-wont-find-dlls/4050/4 "2021-09-09T05:09:46Z")

</div>

Thanks for the replies! I’ll update my script to use `find_file` instead.

As an aside, I was curious how DLLs are located from the find modules that ship with CMake. It appears that there isn’t a common pattern for doing this. I only found 3 cases:

1. FindGSL.cmake assumes the DLL is in the same folder as the lib, so it just does a string replace “.lib” → “.dll”
2. FindGTest.cmake just sets the `IMPORTED_IMPLIB` property, and ignores the `IMPORTED_LOCATION` entirely.
3. FindHDF5.cmake… I honestly have trouble following this one, but it appears to set `IMPORTED_LOCATION` and `IMPORTED_IMPLIB` to the same `*.lib` path, ignoring the DLL entirely.

Thanks again for you help!

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [September 11, 2021, 5:35pm UTC](https://discourse.cmake.org/t/find-library-wont-find-dlls/4050/5 "2021-09-11T17:35:40Z")

</div>

Yeah, it’s usually been “as problems are found, find modules are updated”. It’s really hard to find “perfect” find modules in CMake itself due to the history they tend to have.
