I've got this problem with my makefile
:
gcc -c src/uno.c src/uno.h -o src/uno.o
gcc: fatal error: cannot specify -o with -c, -S or -E with multiple files
How can i create a .o
file with multiple files?
The header files (src/uno.h
in this case) are referenced from within the files, and should not be named again on the command line:
gcc -c src/uno.c -o src/uno.o
You might have to name the directory where to find them, using the -I
flag. But if you #include "uno.h"
in your sources, then gcc will find the file already, as it searches for it in the same directory which also contains uno.c
.
You can compile multiple fils and link them into a single binary, e.g.
gcc -o myApp myAppMain.c myAppUtil.c myAppStuff.c
But that means you'll have to recompile everything if a single source changes, as the intermediate objects are not kept. If you work with object files, there is always one compiler invocation per translation unit.
There is a feature to precompile headers, but in that case, you'd only compile the header, not the uno.c
file. And in any case, this is pretty advanced, so you probably won't need it.
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