Subject: RE: Which way to compile and link for mingw32 and iostreams
From: [email-masked] (Bernard DAUTREVAUX)

4 Dec 1998 12:48:29 -0800
Message-ID: <[email-masked]>
Reply-To: "[email-masked]" <[email-masked]>
To: "[email-masked]'" <[email-masked]>,
        "GnuWin32 Mailing list (Adresse de messagerie)"
	 <[email-masked]>

> 
------------------------------------------------------------------------------
>
> Bernard Dautrevaux
> Microprocess Ingéniérie
> 97 bis, rue de Colombes
> 92400 COURBEVOIE
> FRANCE
> Tel: +33 (0) 1 47 68 80 80
> Fax: +33 (0) 1 47 88 97 85
> e-mail: b. [email-masked]
> 
------------------------------------------------------------------------------
>
>
>
> -----Original Message-----
> From:	[email-masked] [SMTP:[email-masked]]
> Sent:	Thursday, December 03, 1998 02:22
> To:	[email-masked]
> Subject:	Which way to compile and link for mingw32 and iostreams
>
> I'm attempting to compile my C++ program into a Win32 console executable
> (already have DOS, DPMI, and OS/2 done), and have run into something of a
> snag.
>
> I need to use the following non-standard C library functions:
>
> _kbhit()
> _getch()
> _strrev()
> _itoa()
>
> I also want the executable to be independant of any Cygwin files.
>
> If I compile with -mno-cygwin, then __CYGWIN__ isn't defined, and the
> preprocessor doesn't include the headers in the mingw32 directory.
>

Yes, but the problem is not here; the problem is that mingw32 should be 
included in the CPP search path before the standard include directory (as some 
header files are present in both directories and you definitely need the one in 
mingw32 if it exist).

To correct this I change a bit the specs file (see the version I join below).

In this specs file I also add a "-use-msvcrt" flag that allows you to use 
MSVCRT40 instead of the (brain-dead) CRTDLL, taht amongs other shortcomings 
insist on limiting the total size of args+environment passed to a subprocess to 
1024 bytes!...

> If I compile without it, using the headers in the mingw32 directory, I run
> into problems linking with the -mno-cygwin switch.  Specifically,
> undefined references, such as this:
>
> /libstdc++.a(iostream.o)(.text+0x113):iostream.cc: undefined reference to
> `_ctype_' /libstdc++.a(iostream.o)(.text+0x195d):iostream.cc: undefined
> reference to `_impure_ptr'
> /libstdc++.a(streambuf.o)(.text+0x34c):streambuf.cc: undefined reference
> to `__errno' /libstdc++.a(stdiostream.o)(.text+0x14e):stdiostream.cc:
> undefined reference to `__srget' collect2: ld returned 1 exit status
>
> I snipped the path information from the front, and only included one of
> each error, from multiple instances.
>

I got into exactly the same link problems;I also have a problem with finding 
"__errno" in libm.a... __errno is (I think, anyone correct me if I'm wrong) 
defined by cygwin, but on mingw32 I think we have "_errno", so I think we need 
either a corrected mingw32.a and mingw32/errno.h (at least for the errno 
problem, but I hope this is similar for the others) or a version of 
libstdc++.a/libm.a (and probably others) compiled for mingw32, and not for 
cygwin...

> So, how do I compile and link with the mingw32 libraries, without breaking
> iostreams?
>
> My feeling is that I need to compile with the -mno-cygwin switch, and if
> that's the case, I need to know which define to check for the Cygwin
> compiler, so that I include the mingw32 headers instead of the standard
> ones.
>

There is a __MINGW32__ flag defined by the standard specs, but you need either 
to explicitely read from the mingw32 subdirectory for some include files or use 
my patch below that compiles OK but still cause link problems.

Here is the patched specs file (from 
..../cygwin-B20/lib/gcc-lib/i586-cygwin32/egcs-2.91.57/specs); I think this 
could be interesting for others (both the correction in cpp_specs to add 
mingw32 in the cpp search path and the -use-msvcrt flag, that would probably 
better named -mmsvcrt but this needs a gcc modification otherwise cc1 will 
complain about an undefined flag).

Hope this helps a bit,

			Bernard

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".