Skip to content

Conversation

emillon
Copy link
Collaborator

@emillon emillon commented Jul 21, 2025

Closes #2018

This is an "in flux" snapshot of my experiments to make cross-compilation to mingw work.

Status

  • this builds a 5.4 compiler that targets 64-bit mingw
  • ocamlfind doesn't build
  • the branch is very specific to mingw and hasn't been adapted to be generic in term of cross-compilation target

I've based this work on 5.4 because so many cross-compilation fixes have landed in this release cycle. As a consequence, I haven't imported any cross-compilation patch to the compiler. Instead, it relies on just the following sequence of commands to work:

./configure;
make crossopt
make installopt

(I used the upstream instructions)

Remarks

I'd like to list the quirks I faced while doing this:

host vs target confusion

By default, nix was trying to build a compiler with build=linux, host=mingw, target=mingw (a compiler that would run on windows) instead of build=linux, host=linux, target=mingw (a compiler that runs on linux, whose resulting programs run on windows). I thought that this was an issue with the nix environment, but in the end, just passing --target to ./configure fixes the issue.

Bootstrapping flexdll

On Windows, it's necessary to build flexdll to get flexlink working. This can now be bootstrapped directly but it's necessary to fetch submodules for this to work.

Also, nix packages the pthreads implementation separately so it's necessary to alter the default link command to add a -L flag. I haven't found a way to do this with ./configure flags (LD_FLAGS= sets -link -L which passes arguments to the linker and not to flexlink itself) so I patched Makefile.config instead.

.exe extension

For a reason I haven't understood, this produces binaries with the .exe extension. I believe that this extension should be determined by host rather than target, but I'm not sure. I added symlinks.

Next steps

The next failing step is to get findlib / ocamlfind to work. It doesn't seem to find libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cross compiling to windows using mingw

1 participant