FFI & C++ & Cygwin

Peter Strand d98peter@dtek.chalmers.se
Sat, 11 Jan 2003 17:49:11 +0100


On Fri, Jan 10, 2003 at 02:11:35PM +0100, Koen Claessen wrote:
> The C++ stuff compiles fine (using Cygwin's g++). The
> Haskell stuff compiles just fine (using Win Ghc). However,
> at linking time I get the following error:
>   - undefined reference to '_impure_ptr'
>   - undefined reference to 'operator delete(void*)'
>   - undefined reference to 'vtable for ___cxxabiv1::__blahblah'
> These are all things that C++ uses internally.
> I think the problem is that I used Cygwin's g++ compiler and
> that Ghc uses Mingwin's gcc compiler to compile and link.

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)

(i.e. we would like to use /usr/bin/gcc -mno-cygwin as the linker)

I think it should be possible to use -pgml instead of replacing
the binary, but that didn't work for me..

> However, I have tried to recompile the C++ libraries using
> the Mingwin C++ compiler but it starts throwing pages of
> error messages at me.

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


/Peter