Skip to main content.
home | support | download

Back to List Archive

Re: Problem: compiling with static libs

From: Bill Moseley <moseley(at)not-real.hank.org>
Date: Tue May 18 2004 - 17:38:36 GMT
On Tue, May 18, 2004 at 07:06:07AM -0700, Sebastian Rottmann wrote:
> On Mon, 2004-05-10 at 18:26, Bill Moseley wrote:
> > Try 
> > 
> >   --disable-shared=yes
> doesnt work. "configure: error: invalid feature name: shared=yes"

Sorry, I was typing too fast.  ./configure --help (or google) gives the
correct usage. You can use one of these:

    --disable-shared
    --enable-shared=no

Those will be easier than the steps you detailed:


moseley@bumby:~/swish-e$ make distclean >/dev/null

moseley@bumby:~/swish-e$ ./configure >/dev/null && make >/dev/null

moseley@bumby:~/swish-e$ ldd src/.libs/swish-e
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0x40026000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x4011e000)
        libswish-e.so.2 => /usr/local/lib/libswish-e.so.2 (0x4016f000)
        libz.so.1 => /usr/lib/libz.so.1 (0x401a9000)
        libm.so.6 => /lib/libm.so.6 (0x401ba000)
        libc.so.6 => /lib/libc.so.6 (0x401dc000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

moseley@bumby:~/swish-e$ make distclean >/dev/null

moseley@bumby:~/swish-e$ ./configure --disable-shared >/dev/null && make >/dev/null

moseley@bumby:~/swish-e$ ldd src/swish-e
        libxml2.so.2 => /usr/lib/libxml2.so.2 (0x40026000)
        libpthread.so.0 => /lib/libpthread.so.0 (0x4011e000)
        libz.so.1 => /usr/lib/libz.so.1 (0x4016f000)
        libm.so.6 => /lib/libm.so.6 (0x40181000)
        libc.so.6 => /lib/libc.so.6 (0x401a3000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)

libswish-e is not there.

It's not easy to build a *completely static* version of swish because of
libxml2.  There's two problems with libxml2.  First, is that ./configure
runs a special program to get the link line for libxml2 -- so that ends
up specifying the .so library specifically.  Second, most libxml2 buids
include the code for http access, so you would need to then specify the
libraries that libxml2 depends on.

Anyway the normal way with libtool to build a completely
static binary, IIRC is:

./configure -disable-shared CCFLAGS=LDFLAGS="-Wl,-static" CFLAGS=-O2

You need the CFLAGS so that -g is not specified -- which would prevent
static linking.  I think.

But, again, that won't work with swish because of the items listed with
libxml2.

Still, it's possible if you modify libxml2 in the build line and ignore
the errors:

moseley@bumby:~/swish-e/src$ gcc -Wall -O2 -Wl,-static -o swish-e swish.o keychar_out.o dump.o result_output.o  ./.libs/libswishindex.a -lxml2 -lpthread ./.libs/libswish-e.a -lz -lm

/usr/lib/gcc-lib/i486-linux/3.3.3/../../../libxml2.a(nanohttp.o)(.text+0x16a9): In function `xmlNanoHTTPConnectHost':
: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
/usr/lib/gcc-lib/i486-linux/3.3.3/../../../libxml2.a(nanohttp.o)(.text+0x17b4): In function `xmlNanoHTTPConnectHost':
: warning: Using 'gethostbyname' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking

moseley@bumby:~/swish-e/src$ ldd swish-e
        not a dynamic executable

moseley@bumby:~/swish-e/src$ file swish-e
swish-e: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, statically linked, not stripped


There's likely a way to do that all with libtool, but I'm not sure.
I'll check with the libtool list.



> ps. libtool suxxs (my boss forced me to say that ;)

I used to think that -- I found it a bit hard to understand when first
using it, but now find it's very useful for managing the build process.

-- 
Bill Moseley
moseley@hank.org
Received on Tue May 18 10:38:39 2004