Using GCC4 in MAC OSX, Linux and Windows.
Thanks.
Using GCC4 in MAC OSX, Linux and Windows.
Thanks.
Just use the linker option -static
as shown below.
edd@ron:/tmp$ cat helloworld.c
#include <stdio.h>
int main(void) {
printf("Hello, world\n");
}
edd@ron:/tmp$ gcc -o helloworld.dyn helloworld.c
edd@ron:/tmp$ gcc -static -o helloworld.static helloworld.c
edd@ron:/tmp$ ls -l helloworld.*
-rw-r--r-- 1 edd edd 69 2009-08-18 07:09 helloworld.c
-rwxr-xr-x 1 edd edd 6667 2009-08-18 07:10 helloworld.dyn
-rwxr-xr-x 1 edd edd 576348 2009-08-18 07:10 helloworld.static
edd@ron:/tmp$ ./helloworld.dyn
Hello, world
edd@ron:/tmp$ ./helloworld.static
Hello, world
edd@ron:/tmp$ ldd helloworld.static
not a dynamic executable
edd@ron:/tmp$ ldd helloworld.dyn
linux-gate.so.1 => (0xb7efc000)
libc.so.6 => /lib/i686/cmov/libc.so.6 (0xb7d83000)
/lib/ld-linux.so.2 (0xb7efd000)
edd@ron:/tmp$