Compiling ocaml MinGW64 w64

shadinger edited this page May 31, 2012 · 45 revisions
Clone this wiki locally

Compiling ocaml 64 bits on Windows MinGW64-w64

Please note that the entire process takes ~2 hours to complete.

There is an excellent tutorial to install MinGW64, MSYS and compiling most libs here:

Install MinGW64-w64 and MSYS


First download and install the pre-packaged TDM-GCC from here:

Select the MinGW-w64 tdm64-gcc-4.6.1 version:

  • run the installer

  • unselect "Check for updated files on the TDM-GCC server"

  • click on "create"

  • leave the default installation directory: C:\MinGW64

  • unselect "Start Menu Items" and "Add to PATH" if you want to leave your windows environment clean, leave all default packages

  • install

This packaging is nice as it includes both prefixed and unprefixed version of the gcc tools (i.e. both gcc and x86_64-w64-mingw32-gcc).


Then download MSYS from here:

Download (latest).

Unzip the content in C:\msys64 (you should have c:\msys64\bin, c:\msys64\etc...)

MSYS post-install

Run C:\msys64\msys.bat (you need to run this as an Administrator for the postinstall to succeed, then you don't need anymore admin privileges)

Launch the post-install:

sh /postinstall/

This is a post install process that will try to normalize between
your MinGW install if any as well as your previous MSYS installs
if any.  I don't have any traps as aborts will not hurt anything.
Do you wish to continue with the post install? [yn ] y

Do you have MinGW installed? [yn ] y

Please answer the following in the form of c:/foo/bar.
Where is your MinGW installation? c:/mingw64

Creating /etc/fstab with mingw mount bindings.
        Normalizing your MSYS environment.

You have script /bin/cmd
You have both /bin/ftp.exe and /bin/ftp.
Removing /bin/ftp.

Oh joy, you do not have c:/mingw64/bin/make.exe. Keep it that way.

If everythig is okay you should be able to do the following without errors:

ls /mingw
gcc -v

Now create some prefixed version for some popular tools:

cd /mingw/bin
cp ar.exe x86_64-w64-mingw32-ar.exe
cp ranlib.exe x86_64-w64-mingw32-ranlib.exe
cp windres.exe x86_64-w64-mingw32-windres.exe
cp as.exe x86_64-w64-mingw32-as.exe
cp ld.exe x86_64-w64-mingw32-ld.exe
cp strip.exe x86_64-w64-mingw32-strip.exe
cp objdump.exe x86_64-w64-mingw32-objdump.exe

Install git

Hmmm, no easy way to have git under MSYS...

git config --global "your_username"
git config --global "your@email"

Prepare your environment

Create a .profile as follows (in your C:/msys64/home/[user]/.profile):

# Get the aliases and functions
if [ -f ${HOME}/.bashrc ]
  . ${HOME}/.bashrc
export CVS_RSH="ssh"
export EDITOR="/usr/bin/vim"
export HISTSIZE="500"
export PATH="${HOME}/bin:${PATH}"
export FLEXLINKFLAGS="-nocygpath -L C:\MinGW64\x86_64-w64-mingw32\lib"
export OCAMLLIB="C:/ocamlmgw64/lib"
export PATH="${PATH}:/c/flexdll:/c/ocamlmgw64/bin"

Create a .bashrc file as follows (in your C:/msys64/home/[user]/.bashrc):

# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]
  . /etc/bashrc
# User specific aliases and functions
alias ll="ls -l"
alias vi="vim"

Install flexdll

flexdll compilation is a bit of a nightmare due to bootstrapping issues: flexdll needs ocaml to compile, and ocaml needs flexdll to compile.

As a convenience, a native 64 bits flexdll package is located here:

Download the rar file (click on "raw" button) and unrar the content in C:\flexdll directory.

Install findutils

Mingw64/MSYS is lacking the findutils and namely the "find" command. So we need to get it from MSYS32.

Dowload the precompiled findutils from MSYS32:

tar lxvf findutils-4.4.2-2-msys-1.0.13-bin.tar.lzma
cp bin/find.exe /bin
cp bin/oldfind.exe /bin
cp bin/xargs.exe /bin
rm -rf bin

Compile git for MingW64

Compile ocaml

git clone

Make sure to temporarily reinit some environment variables:

export OCAMLLIB=


cd ocaml-win64
cp config/m-nt.h config/m.h
cp config/s-nt.h config/s.h
cp config/Makefile.mingw64 config/Makefile
make -f Makefile.nt world
make -f Makefile.nt opt
make -f Makefile.nt opt.opt
make -f Makefile.nt install

This will install all ocamlfiles into C:\ocamlmgw64

Compile additional libs

Compile zlib

Download zlib-1.2.7 here:

tar zxvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
make -f win32/Makefile.gcc
cp zlib.h /mingw/include/
cp zconf.h /mingw/include/
cp libz.a /mingw/x86_64-w64-mingw32/lib/
cp libz.dll.a /mingw/x86_64-w64-mingw32/lib/
cp zlib1.dll /mingw/bin/
cd ..

compile openssl

Download openssl here:

tar zxvf openssl-1.0.0i.tar.gz
cd openssl-1.0.0i
./Configure --openssldir=/mingw/x86_64-w64-mingw32 mingw64 no-asm
make install_sw  (software only, we don't need documentation)
cd ..

Note: it is currenlty important not to compile in 'shared' mode to force ocaml to statically link with openssl. I didn't find a suitable way to force static linking in opa or ocaml...

compile ocaml modules

compile findlib

You will need a patched version of Findlib 1.2.7. Original Findlib is hosted here

git clone
cd findlib-win64
make all
make opt
make install
cd ..

compile ulex

Ulex is hosted here Download version 1.1 here

gunzip -c ulex-1.1.tar.gz | tar xvf -
cd ulex-1.1
make all
make all.opt
make install
cd ..

compile ocamlgraph

Ocamlgraph is hosted here Download version 1.8.1 here

tar zxvf ocamlgraph-1.8.1.tar.gz
cd ocamlgraph-1.8.1
./configure  _(ignore warning about lablgnomecanvas not found)_
make install
make install-findlib
cd ..

compile camlzip

Camlzip is hosted here Download version 1.04 here

tar zxvf camlzip-1.04.tar.gz
cd camlzip-1.04
make all
make allopt
make install
make installopt
cp zlib.o zlib.cmi zlib.cmx zlib.mli `ocamlc -g -where`/zip
cd ..

Please note that you need to manually copy some zlib.* libraries.

compile cryptokit

Cryptokit is hosted here Download version 1.5 here

gunzip -c cryptokit-1.5.tar.gz | tar xvf -
cd cryptokit-1.5
ocaml -configure
ocaml -build
ocaml -install
cd ..

There is somewhat an inconsistency somewhere in the build process while cryptokit is looked for in lib/ocaml or in lib/ocaml/site-lib.

 cp -r `ocamlc -g -where`/site-lib/cryptokit `ocamlc -g -where`/

compile ocamlssl

Ocamlssl is hosted here Download version 0.4.6 here

git clone
cd ocaml-ssl
export STATIC=1
make install
unset STATIC
cd ..

Compile opalang

From the MSYSGIT window:

git clone
cd opalang
git remote add upstream
git checkout -b win-merge origin/win-merge

From the MSYS window:

cd opalang

Since MSYSGIT doesn't support symlinks on Windows, we need to manually copy the symlinked files:

rm doc/book/hello_web_services/resources
cp -r doc/book/hello_chat/resources doc/book/hello_web_services/
cp libtrx/default.trx libbase/
cp libtrx/default.trx libnet/
cp libtrx/default.trx libirc/
cp libtrx/default.trx ocamllang/
cp libtrx/default.trx protocols/
cp libtrx/default.trx teerex/
cp libbase.mllib ocamlbase.mltop
cp opalang/classic_syntax/parser_path.trx opalang/js_syntax/parser_path.trx
## BROKEN cp packages/experimental/OPAges/Makefile.common packages/experimental/OPAges/opace/
cp ocamllang/ocaml_keywords.trx protocols/
cp ocamllang/ocaml_parser.trx protocols/
cp ocamllang/ocaml_types.trx protocols/
cp opalang/classic_syntax/xml.trx opalang/js_syntax/

Then launch the compilation

make install