C - dynamic linked vs. static linked: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
Zeile 22: Zeile 22:
 
*./hello.static  
 
*./hello.static  
 
  Hallo Welt!
 
  Hallo Welt!
 +
*ldd  hello.static
 +
not a dynamic executable

Version vom 18. September 2022, 16:40 Uhr

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)

Dynamisches Kompilieren und linken

  • gcc -Os -static hello.c -o hello.static
  • ./hello.static
Hallo Welt!
  • ldd hello.static

not a dynamic executable