Am I in the right place?

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

On Tue, 24 Aug 2004 10:13:08 -0400
Ed Leafe <ed at> 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/ What I want to do is be
> able to compile these libs to link to a copy of 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.


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

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/ => /etc/ (0x40016000) => /lib/ (0x40025000)
        /lib/ => /lib/ (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,


More information about the lfs-support mailing list