Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it correct to compile source file with object files together?

Imagine I have file1.c, file2.c. First I compile one file with gcc -c file1.c -o file1.o. Is it OK to compile them together with gcc file1.o file2.c -o prog? I tried it and no errors are shown, but should I compile file2.o first? Is it correct to mix .c and .o files?

like image 271
Vlad Havriuk Avatar asked Oct 29 '25 07:10

Vlad Havriuk


1 Answers

Yes, you can do gcc file1.o file2.c -o prog. You can also do gcc file1.c file2.c -o prog.

GCC will handle compiling file2.c behind the scenes.

like image 67
emlai Avatar answered Oct 31 '25 00:10

emlai