Re: Dinamic Libraries



On Sun, 2006-02-12 at 20:30, Ed Leaver wrote:
On Fri, 2006-02-03 at 09:18, Alexander wrote:
Do anybody use Glib[mm] for load libraries.
Maybe you'll give example?
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Has this been answered yet? I think *everyone* probably dynamically links glibmm at one time or another. I didn't answer when you posted (3 Feb.) because at the time I was using a (somewhat) kludged build environment, and it's easy enough (for me) to give bad advice
even when  I'm reading from the same page.

No need to reduce the simple to an axiom :-)

However, prompted by Murray's tactful advice (plus one *really* bizarre memory error:-), yesterday I switched to a standard CentOS4 gtkmm-2.4 environment.  Dynamic linking couldn't be easier. Basically, pkg-config is your friend, although like most friends, sometimes it needs a little help. (It would also help if we knew how you generate your makefiles. Do you write your own, do you use Automake/Autoconf, or do you just punch Glade's "Build" button and hold your breath?)

Either way, glibmm should be installed on you system in a common area, e.g. /usr/lib on CentOS4:
$> ls /usr/lib/libglib*
/usr/lib/libglib-1.2.so.0
/usr/lib/libglib-1.2.so.0.0.10
/usr/lib/libglib-2.0.a
/usr/lib/libglib-2.0.so
/usr/lib/libglib-2.0.so.0
/usr/lib/libglib-2.0.so.0.400.7
/usr/lib/libglibmm-2.4.a
/usr/lib/libglibmm-2.4.so
/usr/lib/libglibmm-2.4.so.1
/usr/lib/libglibmm-2.4.so.1.0.7
/usr/lib/libglibmm_generate_extra_defs-2.4.a
/usr/lib/libglibmm_generate_extra_defs-2.4.so
/usr/lib/libglibmm_generate_extra_defs-2.4.so.1
/usr/lib/libglibmm_generate_extra_defs-2.4.so.1.0.7

which tells me I'm using glibmm-2.4. Next try pkg-config (actually, next try "man pkg-config":-)
$> pkg-config --libs glibmm-2.4
-lglibmm-2.4 -lgobject-2.0 -lsigc-2.0 -lglib-2.0

This is the information I need for my Makefile's link line, something like
/usr/bin/c++ -L/usr/bin -lglibmm-2.4 -lgobject-2.0 -lsigc-2.0 -lglib-2.0 $(OBJECTS) -o program_name

You can give pkg-config more than one library argument. My Makefile's LDFLAGS command looks thusly:
LDFLAGS = -L/usr/lib -L/usr/X11R6/lib  $(shell  pkg-config --libs gtkmm-2.4 gthread-2.0) -lpopt

The Makefile's link-line then becomes

/usr/bin/c++ $(LDFLAGS) $(OBJECTS) -o program_name

You might not need -L/usr/lib because some c++ linkers (apparently) already know to look there. YMMV. But if you're using Automake/Autoconf this should all be done for you: in an auto-generated Makefile compare e.g. GTKMM_CFLAGS with the result of "pkg-config --cflags gtkmm-2.4" and likewise GTKMM_LIBS with "pkg-config --libs gtkmm-2.4"

I'm using here gtkmm-2.4 because its what I use, and gtkmm depends on glibmm, and pkg-config knows about this dependence and includes the needed glibmm libraries in its output. On most modern Linux systems, dynamic linking of shared libraries is the default, so if your shared libraries are in a standard place e.g. /usr/lib, there shouldn't be any more to it. If your Makefile's link command doesn't come back with any errors, then the linker (usually disguised as /usr/bin/c++ or /usr/bin/gcc) will resolve all the dynamic references and build an executable that knows where to find its dynamic libraries at runtime.

Sometimes some people will try to link their programs using /usr/bin/ld directly, rather than via /usr/bin/c++ or /usr/bin/gcc. I've usually found this to be a bad idea: one can encounter all sorts of frustratingly undefined reference errors...

Hope this helps...

Ed





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