Re: Static linking



Ian Bell wrote:
On Wednesday 01 Oct 2003 6:10 am, Russell Shaw wrote:

snip

If static linking is so hard to do and no one uses it, then why are there
packages such as libgtk2.0-dev on debian that have the static libraries?

dpkg -p libgtk2.0-dev
dpkg -L libgtk2.0-dev

I don't really know, but dynamic linking has always been 'preferred' because it reduces memory requirements.

OTOH, with the rapid development of linux, the libraries soon become out of date and you end up having compatibility libs so you can still run the old code. So running old and new code at the same times ends up loading two libs anyway.

Now that large amounts of memory are cheap I think there is a case for a lot more static linking. The one huge benefit is that ther are no dependencies to worry about so installation is vastly simplified. (suspect I may now need to don flameproof jacket and retire to underground bunker for 50 years for blasheming).

The reason i wanted to statically link is so i can use the libraries with
no optimization (-O0). The shared system libs are optimized with -O2 which
makes things difficult in gdb. Static linked apps are also useful for single-
purpose embedded systems.

I think i found the problem. I assumed that anything starting with "-"
after -Wl was passed to the linker. However, i think everything needs
commas. This works now (mixture of static and dynamic):

gcc -o shapegen main.o gui.o xmalloc.o object.o menu.o dialog.o
    -Wl,-Bstatic,
    -lgtk-x11-2.0,-lgdk-x11-2.0,-latk-1.0,-lgdk_pixbuf-2.0,-ltiff,-lpng,
    -lpangoxft-1.0,-lpangox-1.0,-lpango-1.0,-lgmodule-2.0,-lgobject-2.0,
    -lglib-2.0,
    -Bdynamic,-lfreetype,-lfontconfig,-ljpeg,-ldl,
    -L/usr/X11R6/lib,-lXinerama,-lXi,-lXft,-lm,-lc

I searched google for *days* on how to static-link a gtk app. More
than half the results said it couldn't be done or it didn't work.




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