g++ not compiling with wildcard filenames on Windows
Asked Answered
A

2

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
Argon answered 11/4, 2016 at 11:2 Comment(3)
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)Stamata
@MartinBonner Ok I've switched it over to plain text as requested.Argon
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.Caco
S
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

Stamata answered 11/4, 2016 at 11:9 Comment(2)
Ah I see I normally use Linux and must have created false memories of this working on windowsArgon
I presume that MSYS also handles this for me... this would explain why I swear it was working earlier.Argon
C
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.

Caco answered 16/9, 2016 at 22:9 Comment(2)
g++ *.cpp works perfectly fine for me with mingw-w64 (mingw-builds edition 4.9.2) in windows 10 command promptSilk
For what its worth I was also compiling student submissions with unknown file names.Argon

© 2022 - 2024 — McMap. All rights reserved.