-4

When I intuitively try to run such command

cc -c source.c header.h -o a_name_different_than_source.o

the following error is thrown

cc: cannot specify -o with -c, -S or -E with multiple files

0x6B6F77616C74
  • 2,559
  • 7
  • 38
  • 65
  • 5
    Why do you want to compile "header.h"? Including it in source.c is enough. – flyingOwl Mar 16 '13 at 21:25
  • To compile a single file program, use `gcc -Wall -g source.c -o binprog` and then use `gdb` to debug `binprog`. For programs with several source files and headers, learn to use a builder like `make` (or `omake`) – Basile Starynkevitch Mar 16 '13 at 21:47

2 Answers2

6

Do not put header.h in your command line:

cc -c source.c -o a_name_different_than_source.o

will work.

ouah
  • 142,963
  • 15
  • 272
  • 331
  • I suggest to replace `cc` with `gcc -Wall -g` to get warnings and debugging information and use the GCC compiler. And compiling `source.c` source file into `source.o` object file (to be linked later) is very common. No need to name the object `a_different_name.o` – Basile Starynkevitch Mar 16 '13 at 21:48
0

A .c file does not require you to mention the headers on the command line, GCC takes care of that.

A simple gcc inputFilename -o outfileName should suffice.

ffledgling
  • 11,502
  • 8
  • 47
  • 69