# How to generate .pc (pkg-config) file supporting --prefix of the cmake --install?

**URL:** https://discourse.cmake.org/t/how-to-generate-pc-pkg-config-file-supporting-prefix-of-the-cmake-install/4109
**Category:** Code
**Created:** [September 18, 2021, 12:01am UTC](https://discourse.cmake.org/t/how-to-generate-pc-pkg-config-file-supporting-prefix-of-the-cmake-install/4109 "2021-09-18T00:01:32Z")
**Posts on this page:** 1
**Showing post:** 6

<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: [September 18, 2021, 10:38pm UTC](https://discourse.cmake.org/t/how-to-generate-pc-pkg-config-file-supporting-prefix-of-the-cmake-install/4109/6 "2021-09-18T22:38:04Z")

</div>

Consider the case where someone creates a tarball archive of your project rather than installing directly from the build tree (e.g.via `cmake --install`). They might unpack that tarball anywhere, which is both a desirable capability and common practice. In that scenario, you can’t hard-code the absolute path of the install location in the .pc file.

Perhaps a better solution might be to define your `prefix=...` line in terms of the `${pcfiledir}` variable, something like `prefix=${pcfiledir}/../..`. The following link might be helpful:

[https://bugs.freedesktop.org/show\_bug.cgi?id=62018](https://bugs.freedesktop.org/show_bug.cgi?id=62018)

---

_[View the full topic](https://discourse.cmake.org/t/how-to-generate-pc-pkg-config-file-supporting-prefix-of-the-cmake-install/4109)._
