20

Is there a way to compile all .c files in a given folder by using the command line with GCC compiler ?
I've seen this page for Linux : http://www.commandlinefu.com/commands/view/3230/compile-all-c-files-in-a-directory but couldn't find any equivalent for CMD.

SagiLow
  • 5,721
  • 9
  • 60
  • 115
  • 2
    I guess, there isn't a way, as mostly this wouldn't make sense for the linker. If you have project with multiple source files, you just should use a make file or write a build script which is also easyer to maintain. – dhein Nov 04 '13 at 10:16

2 Answers2

40

I guess gcc itself doesn't have such a parameter.

But you can try the regular wildcard argument of gcc *.c -o Output where the * (wildcard) is to read as "any".

theonlygusti
  • 11,032
  • 11
  • 64
  • 119
dhein
  • 6,431
  • 4
  • 42
  • 74
-7

You can compile your files with following command:

gcc -c -Wall file1.c file2.c file3.c

Here. -Wall will give you all the warnings and errors.

Do not forget to browse to the same directory where these files reside.

jparthj
  • 1,606
  • 3
  • 20
  • 44