Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot specify -c with multiple files

Tags:

c

file

gcc

makefile

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?

like image 320
myself Avatar asked Nov 07 '12 11:11

myself


1 Answers

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.

like image 189
MvG Avatar answered Sep 22 '22 14:09

MvG