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.
Asked
Active
Viewed 4.4k times
20

SagiLow
- 5,721
- 9
- 60
- 115
-
2I 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 Answers
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
-
Use of `*` is known as [globbing](http://www.tldp.org/LDP/abs/html/globbingref.html). – sherrellbc Feb 20 '17 at 00:17
-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