Re: building a library using gtk+



On 5/16/06, Dov Kruger <Dov Kruger stevens edu> wrote:
If I run pkg-config and capture the output, this is what it puts out:
-Wl,--export-dynamic -lgtk-x11-2.0 -lgdk-x11-2.0 -latk-1.0
-lgdk_pixbuf-2.0 -lm -lpangoxft-1.0 -lpangox-1.0 -lpango-1.0
-lgobject-2.0 -lgmodule-2.0 -ldl -lglib-2.0

So I want to build a library that builds in all the links to these
libraries, because the user code does none of this and therefore
shouldn't need to see all this nonsense. My code needs to be built
against the gtk+ code, not the applications built on top of it.

I handle this by making my own .pc file for my library. It's fairly
easy to get your configure script to generate one and install it
correctly, but I could post an example if you like.

One you have a mylibrary.pc installed, your users can compile and link with:

 g++ main.cpp `pkg-config mylibrary --cflags --libs`

and they should never need to see any gtk/glib/whatever nonsense. I
imagine this would be easier than making a static library with the
deps linked in. Although that's possible, it's rather fragile and you
often find yourself losing some functionality (eg. glib's module
loader can stop working).

Plus on some platforms there are cflags (like -pthreads, or
-D_REENTRANT) you need to set with code that links against gtk, even
indirectly. You need a mechanism to do this sanely.

John



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