libtool
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: TODO


From: Gary V. Vaughan
Subject: Re: TODO
Date: Sun, 14 Nov 2004 20:44:19 +0000
User-agent: Mozilla Thunderbird 0.9 (Macintosh/20041103)

Hi Scott!

Scott James Remnant wrote:
On Sat, 2004-11-13 at 15:27 -0800, Jacob Meuser wrote:

>On Sat, Nov 13, 2004 at 10:21:19AM +0100, Ralf Corsepius wrote:
>
>>It's just that their functionality
>>intersects and partially conflicts.
>
>how?
>
>pkg-config is used to give basic information about installed packages.
>libtool is used to build libraries.
>
>pkg-config is used in configure scripts.
>libtool is used in Makefiles.
>
>yes, it's possible to use constructs like
>
>foo.so: foo.o
>    ${CC} ${LDFLAGS} -o foo.so foo.o `pkg-config bar --libs`
>
>in Makefiles, but this is not overlap in a conflicting way.

This is actually exactly what happens when you use pkg-config in a
configure script.  It generates a (e.g.) GLIB_LIBS Makefile variable and
you arrange for the contents of that to be added to the link line --
just like you say here.

The conflict is that pkg-config not only provides the -L and -l needed
to the library, but also those for all of its dependency libraries.

That is a good point.

My main complaint about pkg-config is this:  It is supposed to
make it easier to link with packages that have each been installed
to their own prefix (to support parallel installation of multiple
versions), but in fact it makes things much harder.

Real world example:  I want to link against libgdiplus, which has a
dependency on cairo, so I ask it for the linkflags:

$ pkg-config --libs libgdiplus
Package libgdiplus was not found in the pkg-config search path.
Perhaps you should add the directory containing `libgdiplus.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libgdiplus' found

Fair enough, better tell it where libgdiplus lives:

$ PKG_CONFIG_PATH=/opt/libgdiplus10/lib/pkgconfig

Hmmm... so I have to tell it where cairo is again, even though I've
already specified where the cairo libs are when I linked gdiplus.
Luckily I remember which cairo I linked it against, otherwise it
would report the wrong flags:

$ PKG_CONFIG_PATH=/opt/libgdiplus10/lib/pkgconfig:\
/opt/libcairo02/lib/pkgconfig pkg-config --libs libgdiplus
Package libpixman was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpixman.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpixman', required by 'cairo', not found

Err... so?  How come I need to know what libraries cairo depends
on.  I want to link against libgdiplus!  Okay, I'll run ldd on
libcairo.so to make sure I get the right prefix:

$ ldd /opt/libcairo02/lib/libcairo.so | grep pixman.so
libpixman.so.1 => /opt/libpixman01/lib/libpixman.so.1
$ PKG_CONFIG_PATH=/opt/libgdiplus10/lib/pkgconfig:\
/opt/libcairo02/lib/pkgconfig:\
/opt/libpixman01/lib/pkgconfig pkg-config --libs libgdiplus
Package libpng was not found in the pkg-config search path.
Perhaps you should add the directory containing `libpng.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libpng', required by 'cairo', not found

Geez, here we go again:

$ ldd /opt/libcairo02/lib/libcairo.so | grep png.so
libpng.so.2 => /opt/libpng12/lib/libpng.so.2
$ PKG_CONFIG_PATH=/opt/libdgiplus10/lib/pkgconfig:\
/opt/libcairo02/lib/pkgconfig:\
/opt/libpixman01/lib/pkgconfig:\
/opt/libpng12/lib/pkgconfig pkg-config --libs libgdiplus
Package zlib was not found in the pkg-config search path.
Perhaps you should add the directory containing `zlib.pc'
to the PKG_CONFIG_PATH environment variable
Package 'zlib', required by 'libpng', not found

Anyway, so we go around and around manually finding out the
entire tree of dependencies that will be pulled in by
libgdiplus, until we eventually arrive at this horror:

$ PKG_CONFIG_PATH=/opt/libgdiplus10/lib/pkgconfig:\
/opt/libcairo02/lib/pkgconfig:\
/opt/libpixman01/lib/pkgconfig:\
/opt/libpng12/lib/pkgconfig:\
/opt/zlib11/lib/pkgconfig:\
/opt/libttf21/lib/pkgconfig:\
/opt/libtiff35/lib/pkgconfig:\
/opt/libjpeg6b/lib/pkgconfig:\
/opt/libungif41/lib/pkgconfig pkg-config --libs libgdiplus

So that it can tell me all the prefixes I just looked up
manually (big deal!):

-L/opt/libgdiplus10/lib -L/opt/libcairo02/lib \
-L/opt/libpixman01/lib -L/opt/libpng12/lib \
-L/opt/zlib11/lib -L/opt/libttf21/lib \
-L/opt/libtiff35/lib -L/opt/libjpeg6b/lib \
-L/opt/libungif41/lib -L/usr/X11R6/lib \
-lgdiplus -lgmodule-2.0 -ldl -lgthread-2.0 \
-lcairo -lm -lfreetype -ltiff -ljpeg -lungif \
-lglib-2.0 -lfontconfig -lpixman -lXrender -lX11 \
-lpng -lz

Hmmm... where did it get -lglib-2.0 and friends from, I
didn't specify those paths on PKG_CONFIG_PATH, maybe it
did do something to save me time after all?

$ ldd /opt/libgdiplus10/lib/libgdiplus.so | grep glib-2.0
libglib-2.0.so.0 => /opt/libglib24/lib/libglib-2.0.so.0

Err, no it gave me the wrong flags, so that I'll end up
linking against libglib-2.0 from the linker default search
path.  Better go back and add those to the PKG_CONFIG_PATH
too, along with anything else they might depend on.

And so it goes on.  Like I said, pkg-config is an aberration:
it makes it *harder* for me to link correctly :-(  And worse,
if I try to link this without the help of libtool, it doesn't
even set the runtime loader library search path, so my app
is going to pick up libraries from the wrong directories
when I run it anyway.

So does Libtool.

How would I do this link with just libtool? (note: -n,
-o application and object.o are dummies just to show this
output)

$ libtool -n --mode=link gcc -o application object.o \
/opt/libgdiplus10/lib/libgdiplus.la

And here is what it tells me.  Notice that it automatically
links against the same dependent libraries that I used to
link libgdiplus in the first place, it doesn't force me to
figure out paths to the correct libraries by hand, and it sets
the rpath for me so that the runtime loader will find the same
libraries I'm linking against at compile time.

gcc -o application object.o \
/opt/libgdiplus10/lib/libgdiplus.so \
-L/opt/libttf21/lib -L/opt/zlib11/lib -L/opt/gettext014/lib \
-L/opt/libglib24/lib -L/opt/libiconv19/lib \
/opt/libglib24/lib/libglib-2.0.so \
/opt/gettext014/lib/libintl.so \
/opt/libiconv19/lib/libiconv.so \
-L/opt/cairo02/lib -L/opt/fcpackage22/lib -L/usr/X11R6/lib \
-L/opt/libpixman01/lib -L/opt/libpng12/lib \
/opt/libcairo02/lib/libcairo.so \
-L/opt/libexpat12/lib \
/opt/fcpackage22/lib/libfontconfig.so \
/opt/libexpat12/lib/libexpat.so \
/opt/libpixman01/lib/libpixman.so \
/opt/fcpackage22/lib/libXrender.so -lXext /opt/libttf21/lib/libfreetype.so \
-L/opt/libtiff35/lib -ltiff \
-L/opt/libjpeg6b/lib /opt/libjpeg6b/lib/libjpeg.so \
-L/opt/libungif41/lib /opt/libungif41/lib/libungif.so -lX11
/opt/libpng12/lib/libpng.so -lm \
/opt/zlib11/lib/libz.so -lpthread \
-Wl,-rpath -Wl,/opt/libgdiplus10/lib \
-Wl,-rpath -Wl,/opt/libglib24/lib \
-Wl,-rpath -Wl,/opt/gettext014/lib \
-Wl,-rpath -Wl,/opt/libiconv19/lib \
-Wl,-rpath -Wl,/opt/libcairo02/lib \
-Wl,-rpath -Wl,/opt/fcpackage22/lib \
-Wl,-rpath -Wl,/opt/libexpat12/lib \
-Wl,-rpath -Wl,/opt/libpixman01/lib \
-Wl,-rpath -Wl,/opt/libttf21/lib \
-Wl,-rpath -Wl,/opt/libjpeg6b/lib \
-Wl,-rpath -Wl,/opt/libungif41/lib \
-Wl,-rpath -Wl,/opt/libpng12/lib \
-Wl,-rpath -Wl,/opt/zlib11/lib

And *that* is why I think pkg-config is an aberration.

They're both trying to deal with platforms like Solaris that don't have
a needed-following link loader.

That's a good idea, if we know the linker can find deplibs without
help, we should take advantage of that to shorten the link line!
Please add it to TODO.

It would be far neater if they could co-operate with this.

Okay, I agree that we're not in the business of killing off pkg-config.
And it would certainly make life easier for everyone if libtool could
extract linkflags like above without the -n -o sleight of hand.  With
luck, we could persuade the pkg-config folks to use that to pass back
a correct link line that won't hose their users' builds.

Cheers,
        Gary.
--
Gary V. Vaughan      ())_.  address@hidden,gnu.org}
Research Scientist   ( '/   http://tkd.kicks-ass.net
GNU Hacker           / )=   http://www.gnu.org/software/libtool
Technical Author   `(_~)_   http://sources.redhat.com/autobook

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFBl55rFRMICSmD1gYRArbsAKClNeJ3PdYGUEEs2+/UwHC8l1fNpgCgk73/
yoN7joWunIdd6f1bWuRWaoc=
=Ur5s
-----END PGP SIGNATURE-----

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]