<?xml version="1.0"?>
<!-- name="generator" content="pyblosxom/0.8.1" -->
<!DOCTYPE rss PUBLIC "-//Netscape Communications//DTD RSS 0.91//EN" "http://my.netscape.com/publish/formats/rss-0.91.dtd">

<rss version="0.91">
  <channel>
    <title>Tollef Fog Heen</title>
    <link>http://err.no/personal/blog/</link>
    <description>tfheen's blog</description>
    <webMaster>tfheen@err.no</webMaster>
    <managingEditor>tfheen@err.no</managingEditor>
    <language>en</language>
    <image>
        <url>http://err.no/tfheen.jpg</url>
        <title>Tollef Fog Heen</title>
        <description>Image of Tollef Fog Heen</description>
        <link>http://err.no/personal/blog</link>
        <width>66</width>
        <height>100</height>
    </image>
  <item>
    <title>pkg-config, sonames and Requires.private</title>
    <link>http://err.no/personal/blog/tech/2008-03-25-18-07_pkg-config,_sonames_and_Requires.private.html</link>
    <pubDate>Tue, 25 Mar 2008 18:07 +0100</pubDate>
    <description>&lt;p&gt;This post is both an attempt at replying to &lt;a href=&quot;http://bugs.freedesktop.org/show_bug.cgi?id=15199&quot;&gt;a bug&lt;/a&gt; against
&lt;code&gt;telepathy-glib&lt;/code&gt;, but also an attempt at explaining what
Requires.private do (and don&apos;t).&lt;/p&gt;

&lt;p&gt;I am using Evolution as my example here, not to pick on Evolution or its
authors in any way, but because it&apos;s a convenient example.  Currently,
on Ubuntu Hardy, &lt;code&gt;evolution&lt;/code&gt; links against 75 different libraries.
Amongst those, we find &lt;code&gt;libz.so.1&lt;/code&gt;, &lt;code&gt;libXinerama.so.1&lt;/code&gt; and many more.
I&apos;ll go out on a limb here and claim that Evolution does not call any of
the functions in libXinerama directly.  Let that be the assumption from
here on.&lt;/p&gt;

&lt;p&gt;An obvious question then is, why does &lt;code&gt;evolution&lt;/code&gt; link against
&lt;code&gt;libXinerama.so.1&lt;/code&gt; if it doesn&apos;t use it?  To answer that question, we
need to go back in time to before we had dynamic linking.  If you wanted
to build a binary like &lt;code&gt;evolution&lt;/code&gt; you had to have 75 &lt;code&gt;-l&lt;/code&gt; statements
when you linked and you ended up with the whole code for Xinerama
embedded in your email and calendar client.  For various reasons, we
stopped doing that and switched to dynamic linking where the &lt;code&gt;evolution&lt;/code&gt;
binary just contains a reference to &lt;code&gt;libXinerama&lt;/code&gt;.  At some point we
also grew the ability for libraries to contain those references to other
libraries, so you don&apos;t have to hunt down all the dependencies of
&lt;code&gt;libfoo&lt;/code&gt; when you are linking with it.  We also got tools such as
&lt;code&gt;libtool&lt;/code&gt; which try to abstract away a lot of the problems of building
on older platforms which don&apos;t support inter-library dependencies.&lt;/p&gt;

&lt;p&gt;Now, since &lt;code&gt;evolution&lt;/code&gt; still doesn&apos;t use anything directly in
&lt;code&gt;libXinerama.so.1&lt;/code&gt; but just uses a library which in turn links against
&lt;code&gt;libXinerama.so.1&lt;/code&gt;, it shouldn&apos;t be linking against it.  Then why is it
linked with it?  Again, we need to look back at history, and for this
part I am at least partially responsible.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;pkg-config&lt;/code&gt; was originally written as a replacement for &lt;code&gt;gnome-config&lt;/code&gt;
and various other &lt;code&gt;-config&lt;/code&gt; utilities.  Lots of libraries and
applications now ship &lt;code&gt;.pc&lt;/code&gt; files and we have a standardised interface
for querying those files.  One of the problems the original authors of
&lt;code&gt;pkg-config&lt;/code&gt; faced was the problem of dependencies.  They added
dependencies so the authors of &lt;code&gt;gst-python-0.10&lt;/code&gt; could say &quot;We need
pygtk-2.0 too&quot; and so the compilation flags needed for &lt;code&gt;gst-python-0.10&lt;/code&gt;
would also include those for &lt;code&gt;pygtk-2.0&lt;/code&gt;.  Note that I&apos;m using
&quot;compilation flags&quot; loosely here, I am not just talking about CFLAGS.&lt;/p&gt;

&lt;p&gt;This did not fix the problem of inflated dependencies.  Not at all.  I
talked with some of the Debian Release Managers back in 2004/2005 and
we worked out a solution which should help us have correct, uninflated
dependencies since the then-current way of handling dependencies caused
big problems for migrations of packages between &lt;code&gt;unstable&lt;/code&gt; and
&lt;code&gt;testing&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The plan was to introduce a new field, &lt;code&gt;Requires.private&lt;/code&gt; which would
not show up unless you passed &lt;code&gt;--static&lt;/code&gt; to the &lt;code&gt;pkg-config&lt;/code&gt; invocation
(since you need all libraries if you are linking statically).  This
definition of &lt;code&gt;Requires.private&lt;/code&gt; was mostly useless since GNOME and GTK+
have a habit of including each other&apos;s headers.  To make a long story
short, I changed the semantics so the &lt;code&gt;Cflags&lt;/code&gt; field from private
dependencies were included even when not linking statically.&lt;/p&gt;

&lt;p&gt;A problem which &lt;code&gt;pkg-config&lt;/code&gt; does nothing to guard against in this case
is if you have &lt;code&gt;libfoo.so.2&lt;/code&gt; linking against &lt;code&gt;libbar.so.1&lt;/code&gt; and
&lt;code&gt;libfoo.so.2&lt;/code&gt; exports some of libbar&apos;s types in its ABI (and not just as
pointers, but actual structs and such).  If libbar&apos;s soname is then
bumped to &lt;code&gt;libbar.so.2&lt;/code&gt; and libfoo is rebuilt, libfoo&apos;s ABI has changed
without a soname bump.  This is bad and will cause problems.  If your
application is linked against both &lt;code&gt;libfoo.so.2&lt;/code&gt; and &lt;code&gt;libbar.so.1&lt;/code&gt;,
you&apos;ll still get problems since &lt;code&gt;libfoo.so.2&lt;/code&gt; then suddenly pulls in
symbols from &lt;code&gt;libbar.so.2&lt;/code&gt;.  If you used symbol versioning, you would at
least not get symbol conflicts and your application would continue to
work, but you would have a spurious dependency and the package
containing &lt;code&gt;libbar.so.1&lt;/code&gt; would be kept around until your application was
recompiled.&lt;/p&gt;

&lt;p&gt;With this background, you might ask the question why we still have
&lt;code&gt;Requires&lt;/code&gt; since it is seemingly useless.  For C, it is useless in all
but the most special cases, just use &lt;code&gt;Requires.private&lt;/code&gt; instead (and its
sibling &lt;code&gt;Libs.private&lt;/code&gt;).  Other languages have different semantics.
Some people use &lt;code&gt;.pc&lt;/code&gt; files for other purposes such as
&lt;code&gt;gnome-screensaver&lt;/code&gt; having variables defining where themes and
screensavers go.&lt;/p&gt;

&lt;p&gt;Hopefully this blog post has explained a bit about why we have
&lt;code&gt;Requires.private&lt;/code&gt; and what the difference between this and their
regular counterpart is.  If there&apos;s anything unclear, please do not
hesitate to &lt;a href=&quot;mailto:tfheen@err.no&quot;&gt;contact me&lt;/a&gt;.&lt;/p&gt;
</description>
  </item>
  </channel>
</rss>
