Thursday, March 22, 2012

Static & dynamic compilation of C code

Static compilation
===================
[root@vilalin05 src]# gcc -m64 -static -o server server.c

confirmation check :
1]execute file command
[root@vilalin05 src]# file server
server: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, statically linked, for GNU/Linux 2.6.9, not stripped
[root@vilalin05 src]#
2]execute ldd command
[root@vilalin05 src]# ldd server
not a dynamic executable
[root@vilalin05 src]#



Dynamic compilation
===================
[root@vilalin05 src]# gcc -m64 -o server server.c

confirmation check:
1]
[root@vilalin05 src]# file server
server: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped

2]
[root@vilalin05 src]# ldd server
libc.so.6 => /lib64/libc.so.6 (0x000000386da00000)
/lib64/ld-linux-x86-64.so.2 (0x000000386d600000)
[root@vilalin05 src]#


||END||

No comments:

Post a Comment