Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Date: Fri, 22 Nov 2002 18:00:28 -0800 (PST) From: "Peter A. Castro" To: Andrew DeFaria cc: cygwin AT cygwin DOT com Subject: Re: impure_ptr/Mingw and Cygwin In-Reply-To: <3DDED511.7@Salira.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Fri, 22 Nov 2002, Andrew DeFaria wrote: > I wish to use -mno-cygwin to produce an executable that can work without > Cygwin installed. I have successfully done this before. Now I'm adding > some functionality to my program and it is no longer working! I've > worked it out such that it will compile and link but when my program > runs it simply stops returning an exit code of 5. Running this under gdb > produces a SIGSIGV Segmentation fault then you attempt to run it. > > I've whittled it down to the bare minimum to reproduce the problem. > Seems to me the problem is somewhere between newer versions of gcc 3.X > and Mingw. > > File: foo.c: > > #include > int main (void) { > printf ("Hello World\n"); > fprintf (stderr, "%s\n", "Hello World 2"); > } > > $ gcc -g foo.c -mno-cygwin -I/usr/include -o foo -liberty -lcrtdll -lg > $ foo > $ > > Note that if I do not put -lg then I get: > > /tmp/ccKAyr4S.o(.text+0x4b): In function `main': > /dview/defaria_2.0/salira/neopon/build/maketools/foo.c:4: undefined > reference to `_impure_ptr' > > Any ideas? Well, for one thing, linking with -lg will pull in cygwin.dll since /lib/libg.a is a symlink to libcygwin.a. So your program won't be Cygwin-free, if that's your goal. However, I got it to work with the following command: $ gcc -g foo.c -mno-cygwin -mwindows -o foo -liberty -lmingw32 $ ./foo.exe > x $ cat x Hello World If you change 'stderr' to 'stdout' you get "Hello World 2" in the output too. You'll have to play with carriage control a bit, but basically it works. Windows doesn't really have the concept of a stderr file handle, so this behaviour makes sense to me. I ran the resulting executable through Visual C++'s DUMPBIN program and verified foo.exe only imports msvcrt.dll and kernel32.dll, so it's Cygwin-free. -- Peter A. Castro or "Cats are just autistic Dogs" -- Dr. Tony Attwood -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/