6

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
Community
  • 1
  • 1
DuncanACoulter
  • 2,095
  • 2
  • 25
  • 38
  • Please don't post screen shots: You could have written that as quoted plain text (start each line with ">" and five spaces), and it would have been *much* more readable) – Martin Bonner supports Monica Apr 11 '16 at 11:10
  • @MartinBonner Ok I've switched it over to plain text as requested. – DuncanACoulter Apr 11 '16 at 11:52
  • 1
    I don't think it's a memory failure on your part. I just upgraded versions of GCC (current version 4.9.2) and I'm having to change a Windows batch file that used *.cpp successfully before and now fails to work unless I replace that with specific filenames. – Daniel R. Collins Sep 14 '16 at 03:31

2 Answers2

5

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

Community
  • 1
  • 1
2

I note that TDM is based on the MINGW port of GCC. I've found that different versions of this compiler do in fact treat the wildcard differently. For example, it works perfectly fine for me as of version 3.4.2, compiling in Windows 7:

GCC v.3.4.2 compiling with wildcard on Windows 7

However, when I upgraded to GCC v.4.9.2, this batch file and others I was using broke (specifically, the *.cpp was not recognized). This was a version of MINGW GCC which came with the Dev-C++ IDE. Because I needed this feature rather badly (specifically, test-compiling large submissions of student code with unspecified random filenames), I actually had to downgrade and revert back to the old version for just this purpose.

Daniel R. Collins
  • 893
  • 1
  • 8
  • 22