mingw32 - noncygwin32 gcc - libwinserve.a

Colin Peters colin@bird.fu.is.saga-u.ac.jp
Wed Oct 15 20:01:00 GMT 1997

Earnie Boyd[SMTP:earnie_boyd@hotmail.com] wrote:
>I've also noted that the mingw32 version of gcc (I say that it is gcc 
>because it doesn't matter which shell is used) removes all quotes from 
>the command line.  E.G.: The makefile from bash-2.01 has a command line 
>definition of -DPROGRAM='"bash"'; when the compiler sees this it is 
>trying to resolve the reference to bash as a variable not as a literal.

With the version of gcc I am using (the mingw32 native version linked
to from my homepage) this can be solved by doing the following, extremely
ugly, escaping:

 gcc junk.c "-DX=\"\\\"the X string\\\"\""

gcc gets -DX="\"the X string\"" as a single argument, which is then passed
on to cpp, which does similar stripping and escaping to get -DX="the X string"
as a single argument (gcc junk.c -DX="\"\\\"the X string\\\"\"" should work
too, as should gcc junk.c "\"-DX=\\\"the X string\\\"\""). My source file:

#define	Y	"the Y string"

char szX = X;
char szY = Y;

Gets expanded (-E output) as:

# 1 "junk.c"

char szX = "the X string" ;
char szY = "the Y string" ;

Which sounds like what you want.

This is, of course, with both gcc and cpp compiled using mingw32.

There are options in Mingw32 (at least since 0.1.4, if not earlier)
for turning off "globbing" of the command line from inside a program,
but they do not seem to turn off this escaping and quoting. However,
I don't think it is done by command.com, because it also happens when
a program is invoked through spawn* (I think), and the Win32 API
GetCommandLine returns the command line with the quotes intact in any
case. (If you really needed complete control over the command line
under Mingw32 GetCommandLine plus your own processing is probably the
best you can do.)

Anyway, the short answer to your question of a few days ago about
escaping quotes and such is: yes. There are ways of escaping things
so they get where they need to go in the right form, but you have
to know how many times the escaping is going to be done to get it

How this all plays out when bash or another shell is in the mix trying
to do escaping and quoting as well has not been investigated (by me).

Hope this helps a bit.


-- Colin Peters - Saga Univ. Dept. of Information Science
-- colin@bird.fu.is.saga-u.ac.jp - finger for PGP public key
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".

More information about the Cygwin mailing list