3

Yes, in principle the present question is a duplicate of this one, but that's been asked and answered 12 years ago. The answer might have changed in the meanwhile. And indeed the material I linked to is not that old, so things have definitely changed as far as cross-compilation in general goes; whether that means a different answer exists today for the present question is another thing, and that's why I'm asking.

I have my Linux system where I develop Haskell code , and I came up with a Haskell program that I want to port to Windows. All I can do on the latter is literally copy an executable and run it; I can't install anything on it.

It's a terminal-based program, where I use a bit of System.Console.ANSI for coloring text, clearning the screen, and so on. There I read "platform-independent", so I'm optimistic about porting it to Windows (but regardless, I'm interested in cross-compiling also just a hello world little example).

I manage my Haskell environment with GHCup. I use Cabal, not Stack.

I've skimmed through this page on cross compilation, and what makes me think the answer might be no, or at least not that straightforwardly are the following.

This one, which is the only place in the page where Windows is mentioned:

  • Cross-building a normal compiler: Build on one platform a compiler that runs on, and targets another. Examples:
    • TakeoffGW is a distribution of Unix tools for Windows, built by cross-compiling on a Linux machine. They would like to be able to build and distribute GHC this way. It might be useful for us to be able to cross-compile a Windows GHC from Linux too.
    • build a 64-bit GHC on OS X, by cross-compiling using the 32-bit version.
    • We could port to Win64 (#1884 (closed)) by cross-compiling using a 32-bit Windows GHC.
    • Other porting tasks might be easier, given a suitable cross-compilation toolchain.

and this one, that only mentions Linux,

More targets work in various directions. Some notable ones:

  • x86_64-linux -> aarch64-linux (64-bit LE -> 64-bit LE)
  • x86_64-linux -> armv7a-linux (64-bit LE -> 32-bit LE)
  • x86_64-linux -> m68k-linux (64-bit LE -> 32-bit BE)
  • i386-linux -> powerpc64-linux (32-bit LE -> 64-bit BE)

Have I misunderstood that page, or is it outdated? Can I compile a Haskell program on Linux to make it run on Windows?

6
  • This question is similar to: GHC cross-compiling sources on Linux host for Windows. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem.
    – cafce25
    Commented Jul 6 at 18:38
  • @cafce25, that's 12 years ago! And the question is for its nature (implied by the yet in the answer) subject to change over time.
    – Enlico
    Commented Jul 6 at 18:54
  • If that is so then it's not a question within SOs scope to begin with.
    – cafce25
    Commented Jul 6 at 21:57
  • @cafce25, nobody seem to have complained with that one, though.
    – Enlico
    Commented Jul 6 at 22:31
  • 3
    @cafce, Are you saying that questions whose answers may change over time are out of scope for SO? I am unable to find any other mention of this prohibition. Such a rule could be used to dismiss almost any “How can I …?” question, because technology will change over time.
    – jdgleeson
    Commented Jul 7 at 0:43

0