I am new to C language and I need to know what is the difference between cc filename.c and cc -c filename.c when compiling a C source code. I know that cc -c command creates an object module, if so how to convert that object module into a executable file.
Asked
Active
Viewed 307 times
0
-
Wait, is this asking how to compile object files? It sounds like you already know what the difference between `cc` and `cc -c` is. – Dennis Meng Dec 26 '13 at 04:33
-
Why we need to create an object file? Why don't we directly create the executable file? – buddhi weerasinghe Dec 26 '13 at 09:30
-
@buddhi-weerasinghe In larger applications you normally have many modules, like foo.c, bar.c and main.c. In this case it's more convenient to compile each one with -c and then link the objects at the end to produce the executable. – Brandin Dec 26 '13 at 11:32
1 Answers
2
To create an executable file from object modules, you need to link them using cc
or ld
or some other linker as follows
cc a.o b.o c.o -o final.bin
You can also mention the libraries which you want to link here.
It will generate executable if any of these have atmost one entry point (main function).

doptimusprime
- 9,115
- 6
- 52
- 90