# Force find\_package to fail if required library type (shared vs. static) is not found

**URL:** https://discourse.cmake.org/t/force-find-package-to-fail-if-required-library-type-shared-vs-static-is-not-found/15612
**Category:** Usage
**Created:** [April 21, 2026, 10:14am UTC](https://discourse.cmake.org/t/force-find-package-to-fail-if-required-library-type-shared-vs-static-is-not-found/15612 "2026-04-21T10:14:57Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Lars](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@Lars](https://discourse.cmake.org/u/Lars)
#### Post date: [April 21, 2026, 10:14am UTC](https://discourse.cmake.org/t/force-find-package-to-fail-if-required-library-type-shared-vs-static-is-not-found/15612/1 "2026-04-21T10:14:57Z")

</div>

Note: a similar issue is described in [Choose between shared/static library after find\_package()](https://discourse.cmake.org/t/choose-between-shared-static-library-after-find-package/2910) but the answer is inadequate for some scenarios in my opinion.

Near trivial task: I want to link a shared library against dependencies installed on the system.

Now, to my understanding, CMake `target_link_libraries` does not support linking a shared library against static dependencies (at least I got linker errors when I last tried).

So - I want `find_package` to _fail_ if the installed dependency is a static library, when `BUILD_SHARED_LIBS=ON`.

_Edit:_ The solution should also work for MinGW where it appears shared libraries are split into a `.dll` and a `.dll.a` file. I would expect `find_package` to find the shared library so that I can perform a `get_target_property` for `TYPE` on the found package and the result is `SHARED_LIBRARY`

How would I best accomplish that?

---

<div class="post-metadata">

### Author: ![hsattler](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/59ef9b/32.png) [@hsattler](https://discourse.cmake.org/u/hsattler)
#### Post date: [April 21, 2026, 2:37pm UTC](https://discourse.cmake.org/t/force-find-package-to-fail-if-required-library-type-shared-vs-static-is-not-found/15612/2 "2026-04-21T14:37:51Z")

</div>

> [@Lars](#):
>
> So - I want `find_package` to _fail_ if the installed dependency is a static library, when `BUILD_SHARED_LIBS=ON`.

This is not the meaning of this variable. It just defines shared/static for libraries that your project builds (if not set to a fixed type)

Linking to static libraries is definitely supported. However, you also have to know all transitive libraries or use something like pkg-config or cmake config files.

On some environments, you cannot always easily tell if the lib is shared or static and the property might be UNKNOWN.

---

<div class="post-metadata">

### Author: ![Lars](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/74df32/32.png) [@Lars](https://discourse.cmake.org/u/Lars)
#### Post date: [April 21, 2026, 5:34pm UTC](https://discourse.cmake.org/t/force-find-package-to-fail-if-required-library-type-shared-vs-static-is-not-found/15612/3 "2026-04-21T17:34:13Z")

</div>

> Linking to static libraries is definitely supported. However, you also have to know all transitive libraries or use something like pkg-config or cmake config files.

That’s not my definition of “supported” - if I have to do a lot of workarounds myself in order to accomplish what normally is done with a single line target\_link\_libraries, then it’s not supported by cmake to link a shared library against static dependencies.

This is what I am asking: How do I ensure a controlled error when the user sets BUILD\_SHARED\_LIBS=ON, but the local system has at least one dependency only as a STATIC\_LIBRARY?

The controlled error will look much cleaner than tons of linker errors during the build stage as it happened last time I had this scenario.
