Best practices for setting -rpath in .pc files?

Dan Nicholson dbn.lists at
Tue Aug 24 18:14:20 PDT 2010

On Fri, Aug 13, 2010 at 10:28 AM, Nick Mathewson <nickm at> wrote:
> Hello!
> I maintain a library which (for testing and various other reasons)
> people often want to install into directories not on their usual
> library search path.
> When they do this, is there any sense of whether it's reasonable to
> include an -rpath flag (or a -Wl,-R flag, or a -R flag, or a
> -Wl,-rpath flag as appropriate) in the .pc file?  Or is this a bad
> idea for some reason?

There are reasons against it, but there are also times (as you note)
when setting it is very helpful. libtool adds rpaths for you by
checking if the linked library is in your system's search path. This
is pretty hacky, but it does what you want.

> If this is a reasonable idea, can anybody point me towards an example
> of an autotools-based project that does it correctly, so I can see how
> it's done and not reinvent the wheel?
> (I've checked the documentation and mailing list archives for info
> about this.  If there's anything documented, I'm afraid I haven't
> managed to find it.  Of the projects I've looked at, none seem to take
> this approach, but I don't know whether that's because it's a bad
> idea, or because it's too hard, or whether they just didn't think to
> do it.)

It's kind of tough to handle this from a .pc file since pkg-config
doesn't understand the option, but it might work to shove it in the
Libs: field. I wouldn't suggest that for a distro package, but I think
it would work.

As for a minimal autotooled project using pkg-config and libtool, you
can just add AC_PROG_LIBTOOL (LT_INIT in newer releases) and libtool
will take over the linking from automake. It'll give you the rpaths
you're looking for. Of course there's always "export


More information about the pkg-config mailing list