[Discuss] Compiling a binary

Hans Oeste hoeste at shaw.ca
Thu Sep 21 17:46:31 PDT 2006


I'll give this a try.
 
Thanks
 
Hans 
 
-------Original Message-------
 
From: noel at natnix.com
Date: 09/21/06 15:47:14
To: discuss at vlug.org
Subject: Re: [Discuss] Compiling a binary
 
You may want to link some dynamic libraries statically, but keep the
standard system libraries (like libc) dyncamically.
 
You can use ld -r to statically link a bunch of object files and
dynamic .so files to product anoter linkable static .o file.  Here's
an example that statically links in -lm, but still uses a dynamic libc:
 
    $ cat sin.c
    #include <math.h>
    #include <stdio.h>
    int main() { printf("sin(1)=%f\n", sin(1)); }
 
Statically combine sin.o and -lm into sin_lm.o
 
    $ cc -c sin.c
    $ ld -r -o sin+lm.o sin.o -lm
 
Produce final execuatble liked with dynamic libc
 
    $ cc -o sin+lm sin+lm.o
    $ ldd sin+lm
            libc.so.6 => /lib/tls/libc.so.6 (0x4001f000)
            /lib/ld-linux.so.2 (0x40000000)
 
--Noel
 
 
On Wed, Sep 20, 2006 at 10:43:34PM -0700, Hans Oeste wrote:
> I want to take a program that is currently being compiled to use the
> libraries currently installed i.e. linking to them,  to have the necessary
> libraries compiled into the binary so I can run the program on a computer
> that doesn't have those libraries installed.  Can some-one point me in the
> correct direction for the endeavor?
>
> Hans
> _______________________________________________
> Discuss mailing list
> Discuss at vlug.org
> http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss
_______________________________________________
Discuss mailing list
Discuss at vlug.org
http://ladybug.vlug.org/cgi-bin/mailman/listinfo/discuss
.


More information about the Discuss mailing list