FFI & C++ & Cygwin

Koen Claessen koen@cs.chalmers.se
Sat, 11 Jan 2003 20:49:27 +0100 (MET)

Peter Strand wrote:

 | It is possible to trick ghc into using cygwin's gcc in mingw-mode,
 | the following steps works for me to do that:
 | * compile the c++-stuff with g++ -mno-cygwin
 | * copy /usr/bin/gcc.exe to c:/ghc/ghc-5.04.2/gcc.exe
 | * rename c:/ghc/ghc-5.04.2/gcc-lib to something else
 |    (ghc feeds a -B option to gcc, which we cannot(?) override)
 | * compile with "ghc -optl -mno-cygwin -lstdc++"
 |    (add -optc -mno-cygwin if -fvia-C is used)

Thanks for your reply, Peter. Actually, we tried the above
without the renaming of gcc-lib, and also the -pgml flag

In the end, we found out that the gcc versions of ghc and
mingwin and cygwin did not match up.

So, when we used normal cygwin g++-2, the linking suddenly
produced a lot less error messages. Actually only one:
undefined reference to _impure_ptr. After hours of hacking,
I simply created a C file that defines a constant called
_impure_ptr, and linked that with everything else. It works
now! And it doesn't even crash :-)

 | However, the method above doesn't help if you really
 | need cygwin for your c++-library, which you seem to
 | do?

We found out that the complex makefile system used
cygwin-style paths which the mingwin g++ did not understand
but that was "easily" fixed by replacing mingwin's g++ by a
script that first converts all its arguments which look like
filenames to windows-paths and then calls mingwin's g++.

Anyway, thanks for everyone's suggestions!


Koen Claessen
Chalmers University, Gothenburg, Sweden.