Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I cross compile a haskell program on a linux machine with a windows (PE) target?

I'd like to develop haskell code that will run on windows and interact with windows OS APIs, but I would like to do it on a linux machine. How do I accomplish this? I can compile on a windows machine and that works, but not on a linux machine. Haskell can use a LLVM backend, can't it? Can I use LLVM to accomplish this? Or work with MinGW somehow?

like image 711
user3369300 Avatar asked Mar 01 '14 21:03

user3369300


1 Answers

I tried many possibilities, including GHC on Wine (didn't work for me, despite many notices advertising that it works "out of the box").

For cross compilation, one problem lies in making GHC find your C libraries and DLLs (for windows). Template Haskell will also give you headaches (because it needs to load linux libraries but then compile for windows).

I never managed to get around those problems properly.

In the end, I opted for installing GHC on a Windows VM, and now I use a script to push stuff to a repo, connect to the windows machine via SSH, pull, clean, recompile and test, all executed from a linux CLI and giving me feedback about what's happening on windows.

EDIT: I'm not providing this answer in an attempt to discourage anyone from trying something smarter. I too am interested in real cross-compilation and, if someone has a good solution, I'm all ears. My alternative method always works, but it really is a pain, having to start a VM just for this. Furthermore, it implies using one VM per OS per architecture, which is quite heavy.

like image 171
Ivan Perez Avatar answered Nov 02 '22 04:11

Ivan Perez