# Can't force find\_library to find .dll suffix

**URL:** https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387
**Category:** Usage
**Created:** [June 12, 2020, 10:13pm UTC](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387 "2020-06-12T22:13:01Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)
#### Post date: [June 12, 2020, 10:13pm UTC](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387/1 "2020-06-12T22:13:01Z")

</div>

When executing find\_library in  
find\_library(PostgreSQL\_LIBRARIES NAMES libpq.dll pq  
PATHS  
“${PQ\_ROOT}/src/interfaces/libpq”  
NO\_DEFAULT\_PATH NO\_SYSTEM\_ENVIRONMENT\_PATH NO\_CMAKE\_FIND\_ROOT\_PATH

)  
it debug report indicate  
VAR: PostgreSQL\_LIBRARIES  
NAMES: “libpq.dll”  
“pq”  
…  
find\_library considered the following locations:

…postgresql-9.3.6/src/interfaces/libpq/(lib|)libpq.dll(.dll.a|.a|.lib)  
The item was found at  
…postgresql-9.3.6/src/interfaces/libpq/libpq.a  
So it finds only static and ignores .dll.  
If “pq” is removed , the library is not being found:  
VAR: PostgreSQL\_LIBRARIES  
NAMES: “libpq.dll”  
…  
…/postgresql-9.3.6/src/interfaces/libpq/(lib|)libpq.dll(.dll.a|.a|.lib)  
The item was not found despite valid file is there  
Why is .dll ignored and how to force cmake to find it?

---

<div class="post-metadata">

### Author: ![Gonzalo\_Garramuno](https://discourse.cmake.org/user_avatar/discourse.cmake.org/gonzalo_garramuno/32/265_2.png) [@Gonzalo\_Garramuno](https://discourse.cmake.org/u/Gonzalo_Garramuno)
#### Post date: [June 13, 2020, 12:32am UTC](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387/2 "2020-06-13T00:32:20Z")

</div>

Under Windows, you don’t link against the DLL file but against a stub .lib file. The DLL is used only when running the application. That’s probably what cmake searches for.

---

<div class="post-metadata">

### Author: ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)
#### Post date: [June 13, 2020, 2:02pm UTC](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387/3 "2020-06-13T14:02:41Z")

</div>

This is not “under Windows”, but on Linux cross compiling to run on Windows target using mingw64 toolchain. So the dependent library libpq.dll is built 1st and then libpqxx library also has to be built on Linux, It will be used in the emulator wine and on Windows 10.  
Additional info: Te issue is that when building libpqxx (with libpq as dependent) error comes up:  
Linking CXX shared library libpqxx.dll  
CMakeFiles/pqxx\_shared.dir/objects.a(connection\_base.cxx.obj):connection\_base.cxx:(.text+0x8eac): undefined reference to `\_\_imp\_select’

---

<div class="post-metadata">

### Author: ![yisseamake](https://discourse.cmake.org/user_avatar/discourse.cmake.org/yisseamake/32/897_2.png) [@yisseamake](https://discourse.cmake.org/u/yisseamake)
#### Post date: [July 29, 2020, 10:39pm UTC](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387/4 "2020-07-29T22:39:11Z")

</div>

Thanks, does it mean that for cross compiling the library property LOCATION should be library .dll.a file, not .dll file?

---

<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: [December 30, 2020, 7:55pm UTC](https://discourse.cmake.org/t/cant-force-find-library-to-find-dll-suffix/1387/5 "2020-12-30T19:55:33Z")

</div>

For MinGW environments (cross or native), the [`IMPORTED_IMPLIB`](https://cmake.org/cmake/help/latest/prop_tgt/IMPORTED_IMPLIB.html#prop_tgt:IMPORTED_IMPLIB) property should be set to the `.dll.a` file.
