Search code examples
c++compilationg++wildcardtdm-mingw

g++ not compiling with wildcard filenames on Windows


All of a sudden I seem to be struggling with compiling c++ programs (specifically TDM64 5.1.0) from the command-line on Windows (specifically 10) when using wildcard based filenames. It works fine when the names are given in full. I've done this countless times before with no problem Edit: But not normally on windows... my memories of this working before must be false. What am I missing?

C:\Users\Duncan Coulter\Code>dir *.cpp
 Volume in drive C has no label.
 Volume Serial Number is 9EE6-DBBD

 Directory of C:\Users\Duncan Coulter\Code

2016/04/04  01:35 PM             7 869 LittleMan.cpp
2016/04/04  01:35 PM             1 912 main.cpp
               2 File(s)          9 781 bytes
               0 Dir(s)  90 288 394 240 bytes free

C:\Users\Duncan Coulter\Code>g++ *.cpp
g++: error: *.cpp: Invalid argument

C:\Users\Duncan Coulter\Code>g++ main.cpp LittleMan.cpp

Solution

  • Your problem is where you write:

    g++ *.cpp
    

    g++ is a linux style program, and expects the shell to expand wildcards for it. The windows command shell doesn't do that - it expects individual programs to expand wildcards for themselves.

    The easiest solution is to download cygwin - which does expand wildcards for you. Otherwise the answers to this question may be useful:

    https://superuser.com/questions/460598/is-there-any-way-to-get-the-windows-cmd-shell-to-expand-wildcard-paths