Re: static link w/gtk



On Tue, 24 Nov 1998 15:57:25 -0500 (EST), gtk-list@redhat.com (Christopher Seawood) wrote:
> On Tue, 24 Nov 1998, Jeff Garzik wrote:
> 
>> Matt Rosencrantz wrote:
>> > I have written a utility app in gtk, and now I am trying to give a copy to
>> > my brother, however, he cannot install the gtk libs on his machine.  So, I
>> > would like to link the g* libs statically.
>> 
>> ./configure --disable-shared
> 
> That's fine and dandy if you want to waste time by compiling only static
> libs.  By default, both static & shared libs are built so there should be
> an easy way to use the static libs.  Since gtk-config is used to give the
> cflags and link options, it should also be able to give the user the
> proper flags to link only the gtk libs statically if the gtk package has
> been configured to use static libs.

Good idea, but don't use "-static" for that because that's gcc-on-Linux
specific. Linking with static libs is not trivial but very compiler/OS
dependent. On an SGI IRIX 6.x machine with gcc 2.8.1 the "-static" flag
doesn't work at all, I'll have to use the following commandline instead:

  gcc -o foo foo.o -L/path/to/gtk/lib \
    -Wl,-B,static -lgtk -lgdk -lglib \
    -Wl,-B,dynamic -lXext -lX11 -lm

A more generic solution is:

  gcc -o foo foo.o \
    /path/to/gtk/lib/libgtk.a \
    /path/to/gtk/lib/libgdk.a \
    /path/to/gtk/lib/libglib.a \
    -lXext -lX11 -lm

This one should work on every (Unix) OS. 

Note that on newer Unix platforms this is not static linking, but linking
with an archive of dynamic objects. The effect is the same: you don't need
the .so files.


Erik

-- 
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031,  2600 GA Delft, The Netherlands
Phone: +31-15-2785859  Fax: +31-15-2781843  Email J.A.K.Mouw@its.tudelft.nl
WWW: http://www-ict.its.tudelft.nl/~erik/




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