C - dynamic linked vs. static linked

Aus xinux.net
Zur Navigation springen Zur Suche springen

Hello World Code in C

#include <stdio.h>

int main(void)
{
    puts("Hallo Welt!");
}

Dynamisches Kompilieren

  • gcc hello.c -o hello.dynamic
  • ./hello.dynamic
Hallo Welt!
  • ldd hello.dynamic
	linux-vdso.so.1 (0x00007ffdebfc2000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fc8da2a8000)
	/lib64/ld-linux-x86-64.so.2 (0x00007fc8da489000)
  • ls -lh hello.dynamic
-rwxr-xr-x 1 root root  17K 18. Sep 18:37 hello.dynamic

Statisches Kompilieren und linken

  • gcc -Os -static hello.c -o hello.static
  • ./hello.static
Hallo Welt!
  • ldd hello.static
not a dynamic executable
  • ls -lh hello.static
-rwxr-xr-x 1 root root 795K 18. Sep 18:38 hello.static