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:
.o object 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 .c files at the same time. To compile files individually so they can be linked later, you need -c.a.out. If you don't want your program to be called a.out, you use -o to specify a different name.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With