On Windows, GHC is distributed with gcc and g++, e.g. under ghc-7.6.3\mingw\bin
. From the download page, it is also noted under the windows binary download that the build for Windows "also includes support for compiling C++ files."
I could imagine that distributing these compilers is just for convenience, since Windows doesn't come with any. I could also imagine it is necessary for using the FFI, but I'm not 100% sure. For instance, although GHC will compile .c and .cpp files using it's own gcc/g++ compilers, GHC also provides options to choose whichever compiler and linker you want. And indeed, you can specify your own gcc/g++ and it seems to work. You can even cut GHC out of the loop a little further by compiling the .c/.cpp files in advance, and only invoking GHC to compile the Haskell code and link it all using -pgml
(although the overall effect is the same as using -pgmc
and -pgml
).
Now that seems to work, but does it rely on pure luck that you specify -pgml
and -pgmc
to be a version of gcc that is compatible with what GHC has in mind? In other words, when I use the FFI, am I really only supposed to compile and link everything with GHC invocations?
GHC is generally compatible with many/several versions of GCC (the incompatibilities appear when using the evil mangler).
If you try using other C compilers, you'll have a few low level issues to contend with (flags, asm formats).
Note that more recent GHCs deprecate the C backend in favor of the LLVM backend, making this somewhat moot for day-to-day Haskell development.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With