12

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?

Will Ness
  • 70,110
  • 9
  • 98
  • 181
Ein
  • 1,553
  • 3
  • 15
  • 22
  • 1
    Using GHC for everything is generally the easiest way. And (I may be mistaken) if I recall correctly, things don't work too well if you try to use MSVC (and I have the vague memory that Cygwin has problems too). – Daniel Fischer May 22 '13 at 12:58

1 Answers1

11

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.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • 2
    So if I've wrapped my head around this, the 'C backend' and the 'LLVM backend' (and the 'native code generator') all refer to a stage shortly before generating the object file for each Haskell module. The evil mangler is part of the C backend only. Excluding then the C backend, one can expect compatibility of GHC's object files (from .hs files) with GCC's object files (generated from .c/.cpp files) --- for some unspecified range of nearby GCC versions. But for any backend (including LLVM?) you have those low level issues if you use a non-GCC compiler. – Ein May 22 '13 at 17:09