Re: [gtk-list] NEWBIE: Static Linking



Matt Long wrote:
> 
> I'm sure this is a stupid question, but I just don't know the answer.
> Yesterday Aaron, Faby posted a message on why his app was so big and how
> to compile it so that it was dynamically linked. The answer that he came
> up with sounded like it might be related to my question. I would like to
> be able to ensure the opposite. I want to ensure my application is
> statcially linked. I thought the -g had something to do with that, but
> apparently (according to the man page) -g is just for debugging info. I
> also noticed in the man page that there is a linker flag there called
> -static. So what I was wondering is, what is the default action when
> compiling gtk+ apps with gcc. Do they link statically automatically or
> do I have to specify some kind of flag (-static, or something)?
> 
> Thanks in advance.
> 
> -Matt
> 

When I build the rpms for my redhat system, the static libs are not
installed. So I built my own debug, static libs from the source
tarballs. Use this:

# For glib:
[prompt]$ ./configure --enable-shared=no --enable-static=yes \
  --enable-debug=yes --enable-mem-check=yes \
  --enable-mem-profile=yes
[prompt]$ make

# For GTK+
[prompt]$ ./configure --enable-shared=no --enable-static=yes \
  --enable-debug=yes
[prompt]$ make

Then, do link with these new libs, add this to your Makefile:

# -- Begin Makefile example --
GTK_VERSION     = `gtk-config --version`
GLIB_VERSION    = `glib-config --version`

ifeq ($(DEBUG),yes)
  # Use this for debugging
  PREFIX        = /usr/local/src
  GTK_DIR       = $(PREFIX)/gtk+-$(GTK_VERSION)
  GLIB_DIR      = $(PREFIX)/glib-$(GLIB_VERSION)
  GTK_LIBS      = $(GTK_DIR)/gtk/.libs/libgtk.a
$(GTK_DIR)/gdk/.libs/libgdk.a \
                  $(GLIB_DIR)/gmodule/.libs/libgmodule.a
$(GLIB_DIR)/.libs/libglib.a \
                  -L/usr/X11R6/lib -L/usr/lib -rdynamic -lglib -ldl \
                  -lXext -lX11 -lm
else
  # Use this for production
  GTK_LIBS  = `gtk-config --libs`
endif

debug:
	DEBUG=yes make

# -- End Makfile example --

Then, to link against the static libs, just type:
[prompt]$ make debug

You can change to configure enables for your needs. I noticed the
executable grew about ten fold doing this, but if you want to debug, it
helps. The thing I like about this the most is that you don't have to
install the debug libs, so they can peacefully co-exist with the
normally installed libs.

Hope this helps.

Ted Roth


-- 
Email: <troth@netmagic.net>  Web site: <http://www.netmagic.net/~troth>
------------------------------------------------------------------------
"Cat's Motto: No matter what you've done wrong, always try to make
it look like the dog did it."
                                          --- Unknown



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