The project that uses OCaml wants to use Unicode support added in 4.07. The compilation process is happening on Windows XP so the output binary can be run on XP\Vista\8\10 and 11.
Is there any way to get OCaml “4.07.0+default-unsafe-string+mingw32” working for Windows XP SP3?
I have Cygwin for windows xp working with all dependencies, but opam doesn’t run (dll error), OCaml copied from win7 doesn’t run either (The procedure entry point _putenv_s could not be located in the dynamic link library msvcrt.dll.)
Recent version’s of gcc, mingw-w64 and OCaml have all dropped Windows XP support long time ago. If you use recent versions of them to compile your program, it won’t run on Windows XP.
You can try to use a more recent version of Windows as your build os (vista should be ok).
Install an old version of cygwin and the mingw toolchain ( mingw64-i686-gcc-core, mingw64-i686-runtime, mingw64-i686-headers ) from: Cygwin Time Machine
Install opam manually inside cygwin.
bootstrap an old OCaml version, e.g. opam switch create 4.07.0+default-unsafe-string+mingw32
compile your program
test, if the generated binary works under XP.
Caveats:
OCaml stopped supporting Windows XP silently. It’s not documented inside Changes that the corresponding PR uses features that are only available on Vista or later.
Older compiler descriptions from opam-repository-mingw are patched, otherwise they would not longer work with recent versions of gcc/mingw-w64. I’ve never checked, if the changes are compatible with ancient versions of gcc/mingw-w64.
I’m aware of the drawbacks but I’m afraid that dropping support for Windows XP is not an option for the project. And It’s not my decision to make. I will share your concerns with the project mantainer.
@fdopen Using old Cygwin version, after many attempts, I was not able to install opam on vista. The opam init fails without downloading any kind of repository. I will try one more time using Windows 7 but from what I know, the produced binary doesn’t work on Windows XP.
Many thanks for these detailed instructions. Even I’m tech-savvy, I think those will still be a challenge for me. So first let me clarify some things:
By saying ‘I have up and running XP SP3 VM’ are you saying that you have Cygwin setup that allows for the compilation of 4.07.0+default-unsafe-string+mingw32 there?
Does apply those patches mean that I would also need to use Windows XP for compilation? Or those patches are to fix ‘produced binaries’ so the compilation on Windows 7/10/11 will produce a working executable for Windows XP?
What exactly bootstrap flexdll means? I saw this step when I try to compile OCaml, does apply the patch to the ocaml source will be enough?
Yes, my Windows XP VM compiles OCaml (that’s of course not strictly the same thing as installing opam and building that specific package). However, the patch to win32.c should be enough to allow you to build a binary on Windows 10 and run it on Windows XP (but I haven’t tested that).
Bootstrapping flexdll means dumping the flexdll sources in flexdll/, patching them, and then running make flexdll before running make world.opt. The flexdll patches are necessary to answer your original question to get OCaml 4.07 working on Windows XP - that’s not necessary if you patch OCaml 4.07 from Windows 10 and copy the binaries back.
@dra27 I can successfully apply the patch but I face the following problem:
When I’m using opam switch create 4.07.0+default-unsafe-string+mingw32 I can find win32.c file at .opam\4.07.0+default-unsafe-string+mingw32\.opam-switch\sources\ocaml-variants.4.07.0+default-unsafe-string+mingw32\byterun and I can successfully apply the patch.
But the ocaml is already compiled so ocaml bin doesn’t have it.
Before using opam switch create I cannot find win32.c file anywhere inside .opam dir.