Saturday, January 26, 2008

Compile hello.c in steps

How ?



main (void)
printf ("Hello, world!\n");
return 0;

one way to do : "gcc hello.c "

Lets do it step by step :

cpp hello.c > hello.i

hello.i will have all macros expanded.

gcc -Wall -S hello.i

check for hello.s - yep its assembly language code

as hello.s -o hello.o

Now Object file time, created object file using -o option

now ld time but LD need to have a lot options so lets go for

gcc hello.o

this links and create a.out

run a.out and see "Hello, world!".

too long ?? k just use --save-temps options in gcc, all temp files will be saved

'gcc --save-temps hello.c' and do an ls after :-)

tools for help:

file : identifies the file type and some of its characteristics
nm : shows symbol table
ldd : shows list of shared libraries an executable needs

© yankandpaste®

No comments: