4

My OS is Windows 10. I'm using command prompt this time to compile.

according to the book that I am reading, to compile all the source files and make it an object files, (in the current directory) do it by typing this command:

gcc -c *.c

it says the operating system will replace *.c with all the C filenames

But why am I getting this error?

gcc: error: *.c: Invalid argument
gcc: fatal error: no input files
compilation terminated.

I'm in the right directory. And when I compile my source files with their respective names, it's working properly. But the '*.c' is not working.

And the same error in linking the object files using '*.o'

Is that command not for windows OS? If not, what is for windows?

Newbie here.

gsamaras
  • 71,951
  • 46
  • 188
  • 305
Bicolano
  • 90
  • 10
  • 3
    Cross network duplicate [here](https://superuser.com/questions/460598/is-there-any-way-to-get-the-windows-cmd-shell-to-expand-wildcard-paths). I suggest you install a unix shell simulator and avoid using the windows command prompt. Cygwin is one such possible simulator. – StoryTeller - Unslander Monica Aug 13 '17 at 13:43
  • Are you sure that you have at least one `.c` file in the current working directory? Otherwise `*.c` won't be expanded, hence `gcc` receives single command-line argument `*.c`. – Grzegorz Szpetkowski Aug 13 '17 at 13:48
  • @GrzegorzSzpetkowski. Yes sir. I'm in the right directory. – Bicolano Aug 13 '17 at 13:50
  • @StoryTeller.. Tnx sir.. I'll read it. – Bicolano Aug 13 '17 at 13:50

2 Answers2

7

On Unix systems and environments (like MSYS or Cygwin) , wildcards are expanded by the shell (depends), but in Windows CMD, wildcards are expanded and interpreted by the program that receives. This sounds strange, but cmd.exe does not support wildcard expansion (as an interpreter), but some of its built-in commands do, like COPY.

Use a simple program to verify it.

#include <stdio.h>
int main(int argc, char *argv[]){
    int i;
    for (i = 1; i < argc; i ++)
        printf("%s\n", argv[i]);
    return 0;
}

Sample output on Unix:

$ ./a.out /*
/bin
/boot
/dev
...
/usr
/var
$ ./a.out /\*
/*
$

Sample output on Windows:

C:\Windows\system32>a.exe C:\*
C:\*
C:\Windows\system32>

If you want to let something else expand the wildcard for your program, use MinGW (MSYS) or Windows Subsystem for Linux (Win 10 1607 and later).

iBug
  • 35,554
  • 7
  • 89
  • 134
0

In Windows, wildcards are not supported, thus the error you see.

In UNIX though, what you used, would be correct:

Georgioss-MacBook-Pro:~ gsamaras$ nano main.c
Georgioss-MacBook-Pro:~ gsamaras$ nano fun.h
Georgioss-MacBook-Pro:~ gsamaras$ nano fun.c
Georgioss-MacBook-Pro:~ gsamaras$ gcc -c *.c
Georgioss-MacBook-Pro:~ gsamaras$ 
gsamaras
  • 71,951
  • 46
  • 188
  • 305
  • 1
    Mingw manages it internally. in linux I think it is shell dependant – 0___________ Aug 13 '17 at 13:52
  • 1
    You'd better clarify your answer as ***In Windows CMD***. Emulated Unix environments like Cygwin still processes wildcards for CLI programs. – iBug Nov 10 '17 at 15:27