There are several ways to compile and distribute OCaml on Windows. This installer distributes the native, mingw-w64, 64-bit port of OCaml along with a native, 64-bit OPAM. The installer offers to install Cygwin so that you get 1) the proper compiler toolchain needed to use ocamlopt and 2) Unix tools such as make, bash and others, which most packages depend on.
Quick start guide
- open a Cygwin terminal, then opam init
- decline the offer to customize your ~/.bash_profile;
instead, add the following into your ~/.bashrc:
export CAML_LD_LIBRARY_PATH=$HOME/.opam/system/lib/stublibs:/cygdrive/c/OCaml/lib/stublibs export MANPATH=$HOME/.opam/system/man:$MANPATH export PATH=$HOME/.opam/system/bin:$PATH
- you probably want: opam install depext depext-cygwinports
- sample package installation: opam depext sqlite3 && opam install sqlite3
If you already have Cygwin64 installed
Then, skip the Cygwin part of the installer, and make sure you have the following packages: wget, make, automake, m4, mingw64-x86_64-gcc-core, mingw64-x86_64-gcc-pkg-config, patch, rlwrap, libreadline6, diffutils
- If OPAM complains about curl, this is a lie, it actually needs wget
- make sure OCAMLLIB is set using a Windows-style path (e.g. C:/OCaml/lib)
- the output of ocamlopt -config should contain native_c_compiler: x86_64-w64-mingw32-gcc …; if that's not the case, then which ocamlopt will help you figure out what's going on
- if you get errors with depext, check that OPAM's bin folder is in your path, and check that x86_64-w64-mingw32-pkg-config is installed
The installer has been tested on Windows XP, Windows 7, Windows 8.Installer for 64-bit OCaml 4.02.3 + OPAM
- 32-bit OCaml 4.02.3 + Cygwin32 OPAM (Note: opam install merlin works with this one, but not depext-cygports. This is a stock OPAM.)
- 32-bit OCaml 4.02.3 + findlib + batteries
- other old (minor) versions
The full story
See my entry on the Gagallium blog for the (outdated) details.
- The compiler binaries (ocamlc, ocamlopt, etc.) are compiled with x86_64-mingw64: they are native windows programs.
- ocamlopt generates native windows programs: ocamlopt depends on x86_64-mingw64.
- Cygwin is used as a development environment, because it packages mingw (needed for ocamlopt to work properly), as (needed for ocamlopt) and other Unix tools required by ocamlbuild and others.
- opam for Windows comes from David Allsop's fork; it has been patched by yours truly in order to, among other things, point to Andreas Hauptmann's OPAM repository by default.
- Andreas' repository contains patched packages (so that more of them build on Windows); it also contains depext-cygwinports, an OPAM plugin that is capable of fetching system dependencies as cygwin packages for the x86_64-mingw64 toolchain. Concrete example: opam depext ssl will call into Cygwinports to make sure that openssl gets installed into your Cygwin setup for the right toolchain.
The project lives on GitHub. Please file any bug in the "Issues" section there.
The README there should contain enough information to get you (roughly) started if you want to repackage the installer yourself.