# Packaging static libraries for Fedora

**URL:** https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590
**Category:** Code
**Created:** [February 17, 2025, 5:36am UTC](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590 "2025-02-17T05:36:19Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![opoplawski](https://discourse.cmake.org/user_avatar/discourse.cmake.org/opoplawski/32/3829_2.png) [@opoplawski](https://discourse.cmake.org/u/opoplawski)
#### Post date: [February 17, 2025, 5:36am UTC](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590/1 "2025-02-17T05:36:19Z")

</div>

Fedora’s packaging guidelines for static libraries are to put them into a separate -static sub-package that is not required by the main -devel sub-package. However this causes problems for most CMake projects because the cmake target expects the static archive to be present event when not using it and you get errors like:

```auto
-- HDF5 find comps: C;shared
CMake Error at /usr/lib64/cmake/hdf5/hdf5-targets.cmake:305 (message):
  The imported target "hdf5-static" references the file

     "/usr/lib64/libhdf5.a"

  but this file does not exist. Possible reasons include:

  * The file was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and contained

     "/usr/lib64/cmake/hdf5/hdf5-targets.cmake"

  but not all the files it references.

Call Stack (most recent call first):
  /usr/lib64/cmake/hdf5/hdf5-config.cmake:185 (include)
  CMakeLists.txt:286 (find_package)

```

Is there an easy way we can avoid this?

---

<div class="post-metadata">

### Author: ![opoplawski](https://discourse.cmake.org/user_avatar/discourse.cmake.org/opoplawski/32/3829_2.png) [@opoplawski](https://discourse.cmake.org/u/opoplawski)
#### Post date: [May 10, 2025, 2:09am UTC](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590/2 "2025-05-10T02:09:25Z")

</div>

Anyone? This is a very common issue we face in Fedora packaging. It also comes up when one would want to split a large project up to avoid some dependencies if possible.

---

<div class="post-metadata">

### Author: ![opoplawski](https://discourse.cmake.org/user_avatar/discourse.cmake.org/opoplawski/32/3829_2.png) [@opoplawski](https://discourse.cmake.org/u/opoplawski)
#### Post date: [May 14, 2025, 1:59pm UTC](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590/3 "2025-05-14T13:59:52Z")

</div>

So the general methodology we have come up with goes as follows:

- Export the static targets to a separate file:

```auto
export ( EXPORT LIBTargets_static ${CMAKE_CURRENT_BINARY_DIR}/LIBTargets_static.cmake )
install ( EXPORT LIBTargets_static DESTINATION ${PKGFILEDIR}/cmake/LIB )

```

- Include that file with OPTIONAL in the cmake config file so there is no error when it is missing:

```auto
if ( @BUILD_SHARED_LIBS@ )
include ( ${CMAKE_CURRENT_LIST_DIR}/LIBTargets.cmake )
endif ( )
if ( @BUILD_STATIC_LIBS@ )
include ( ${CMAKE_CURRENT_LIST_DIR}/LIBTargets_static.cmake OPTIONAL )
endif ( )

```

Does that seem like a good approach in general? Other things to consider? Any way that cmake could make this easier to achieve?

For background:

- [⚙ D32668 CMake: Split static library exports into their own export file](https://reviews.llvm.org/D32668)
- [WIP: Move static targets into separate exports to allow splitting them off… by opoplawski · Pull Request #946 · DrTimothyAldenDavis/SuiteSparse · GitHub](https://github.com/DrTimothyAldenDavis/SuiteSparse/pull/946)

---

<div class="post-metadata">

### Author: ![opoplawski](https://discourse.cmake.org/user_avatar/discourse.cmake.org/opoplawski/32/3829_2.png) [@opoplawski](https://discourse.cmake.org/u/opoplawski)
#### Post date: [December 14, 2025, 2:50pm UTC](https://discourse.cmake.org/t/packaging-static-libraries-for-fedora/13590/4 "2025-12-14T14:50:59Z")

</div>

Just adding a note that it is import to **NOT** use `-static` as the suffix to avoid automatic include from the generated targets file loading the various build types (`-release`, etc).
