This is the mail archive of the
mailing list for the Cygwin project.
I: gcc ... -U_WIN32 ... may cause problems
- To: "gnu-win32 at cygnus dot com" <gnu-win32 at cygnus dot com>
- Subject: I: gcc ... -U_WIN32 ... may cause problems
- From: Michael Czapski <MCzapski at openplus dot com dot au>
- Date: Thu, 27 Aug 1998 22:54:55 +1000
- Organization: .
- Reply-To: "MCzapski at openplus dot com dot au" <MCzapski at openplus dot com dot au>
I am currently working on a 'source-portable' application, intended to run
natively under Win32, various flavours of Unix as well as OpenVMS. Usually I
develop using Microsoft Developer Studio (VC++ 5.0, Intel), re-build and test
under Cygwin32 B19.3 (EGCS 1.0.2), re-build and test on Linux (gcc 2.7.2,
Intel), re-build and test on OpenVMS/VAX 7.0 (DECC 5.5). This arrangements
allows me to conveniently test and resolve 'gross' portability issues. When I
am sufficiently far advanced with the project I will build the application on
DEC Unix, OpenVMS/AXP and, possibly, other platforms.
I use the same GNUmakefile for Cygwin32 and Linux (will use for other Unix(es)
as well). Since gcc under Cygwin32 does not pre-define "__unix__" or "__unix"
or "unix", as is the case under Linux, and in the Cygwin32/EGCS/gcc environment
_WIN32 is defined the same as in the MS VC++ environment I had to code
#if defined(_WIN32) && !defined(__CYGWIN32__) in a number of places. This was
required to ensure that Windows NT-specific service code is not compiled under
Cygwin32 but unix-specific daemon code is compiled instead, for example. To
avoid coding #if defined construct as shown I decided to undefine _WIN32 when
compiling in Cygwin32 environment by using a command line of a form "gcc ...
-U_WIN32 ...". Before I did that the application worked fine however as soon
as I did undefined _WIN32 it started to misbehave.
It turned out, after some investigations, that the 'stat' system call, which
worked fine with _WIN32 defined, no longer works and causes stack corruption
with the resulting SEGV. It turned out, after further investigation, that the
'missing' _WIN32 affects unistd.h header file. If _WIN32 is defined just prior
to #include <unistd.h> and undefined just after all is well otherwise the
problem repeats. It turned out, after further investigation, that
'__MS_types__' is defined in unistd.h and that this is what makes all the
Now I code that as:
#if defined(__CYGWIN32__) && !defined(_WIN32)
# define __MS_types__ /* this breaks stat function if not defined */
# define _MS_types_DEFINED /* at the time unistd.h is included */
#if defined(__CYGWIN32__) && defined(_MS_types_DEFINED)
# undef __MS_types__
# undef _MS_types_DEFINED
This way I avoid defining _WIN32, can safely (?) undefine _WIN32 and code on
the basis of 'if _WIN32 is not defined than it must be Unix or VMS' :-).
Since I found that workaround I stopped poking around to see what exactly
breaks the 'stat'. If anyone knows or finds out please let me know :-).
This message may, perhaps, save somebody a great deal of hassle in the future
Thanks Cygnus, Sergey and all other contributors for Cygwin32 and all related
For help on using this list (especially unsubscribing), send a message to
"email@example.com" with one line of text: "help".