When I created makefile, I wrote
test: main.o 1.o gcc -o test main.o 1.o main.o: main.c a.h gcc -c main.c 1.o: 1.c a.h gcc -c 1.c
but I don’t get why I use -o in the first line and -c in the second, third line.
What’s the difference between them?
Those options do very different things:
- -c tells GCC to compile a source file into a
.oobject file. Without that option, it’ll default to compiling and linking the code into a complete executable program, which only works if you give it all your
.cfiles at the same time. To compile files individually so they can be linked later, you need
- -o sets the name of the output file that GCC produces. You’re using it when linking object files to make a complete program, and the default output filename for that is
a.out. If you don’t want your program to be called
a.out, you use
-oto specify a different name.
Answered By – Wyzard