Am I in the right place?

Matthew Burgess matthew at linuxfromscratch.org
Tue Aug 24 07:30:09 PDT 2004


On Tue, 24 Aug 2004 10:13:08 -0400
Ed Leafe <ed at leafe.com> wrote:

> I have a rather ambitious goal: I want to be able to create an 
> executable program along with all of the libraries it needs so that I 
> can distribute it to any Linux system and have it run. I am not able
> to do that currently, since many of these libraries have a compiled-in
> link to basic libs such as /lib/ld-linux.so.2. What I want to do is be
> able to compile these libs to link to a copy of ld-linux.so.2 in their
> own directory, so that I can distribute them as a self-contained 
> functioning unit.

This sounds like you just want to pass the "-static" option to 'gcc' in
order to statically compile your source code, as opposed to have it
dynamically link to libraries at run-time.

Consider:

-----hello.c-----
#include <stdio.h>
int main() {
  printf ("Hello World\n");
  return 0;
}
-----hello.c-----

Now, compile this with:

gcc -o hello hello.c
gcc -static -o hello-static hello.c

And compare the output of `ldd`:

-----
bash-3.00$ ldd hello
        /etc/libcwait.so => /etc/libcwait.so (0x40016000)
        libc.so.6 => /lib/libc.so.6 (0x40025000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
bash-3.00$ ldd hello-static
        not a dynamic executable
-----

You should be able to copy hello-static across to any linux machine and
have it run, I believe (assuming your binary isn't reliant on particular
linux-kernel features).

Hope this helps,

Matt.



More information about the lfs-support mailing list