Skip to content
This repository has been archived by the owner on Apr 7, 2021. It is now read-only.
Pierre Courtieu edited this page Jan 4, 2017 · 27 revisions

These are the (most comprehensive) instructions to get a working OPAM setup.

These instructions are optimized towards compiling miTLS and F*.

Sanity checks

  • Open up a cmd.exe prompt, and make sure that typing bash and tar results in a 'bash' is not recognized as an internal or external command error. If cmd.exe picks up any of these two programs, uninstall them. Possible culprits:
    • bash for windows (the new linux syscall emulation layer in windows 10)
    • gnu on windows
    • git for windows (comes with its own msys distribution)
    • msys
    • etc. etc.
  • If you already have cygwin installed: make sure it's cygwin64 (uname -a).
  • If you already have cygwin installed: open up a cygwin terminal, and run where ocaml and where flexlink. If you get anything at this stage, clean up. Possible culprits include:
    • cygwin packages for ocaml and flexdll; remove these!
    • leftover Wodi setup
    • leftover old OCaml setup (e.g. the old 3.11 installer, ocpwin, etc.)
  • Open up a cmd.exe prompt, and run set. If you have any environment variable for OCaml (e.g. OCAMLLIB), clean it up using your system properties → environment variables dialog.

Run the installer

Download and launch the installer from http://protz.github.io/ocaml-installer/; follow the setup instructions and make sure all of the packages below are installed.

Note: on Windows 8.1 and above, the OCaml installer will fail to launch Cygwin's setup.exe. In that case, launch it manually (it has been downloaded to your desktop).

Here's the list of Cygwin packages you'll need (the installer doesn't pre-check all of them).

  • automake
  • diffutils
  • libreadline
  • make
  • m4
  • mingw64-x86_64-gcc-core
  • mingw64-x86_64-gmp
  • mingw64-x86_64-openssl
  • mingw64-x86_64-pkg-config
  • mingw64-x86_64-sqlite3
  • patch
  • rlwrap
  • unzip
  • wget
  • git

Run the second part of the sanity check again, to make sure you still have one ocaml and one flexlink binary.

Configure your initial OPAM setup

In Cygwin Terminal, run opam init, and decline to let it customize your ~/.bash_profile. Instead, add the following to your ~/.bashrc (c:\cygwin64\home\<yourlogin>\.bashrc) (DON't use notepad, use emacs or some other advanced editor, otherwise newline characters will be messed up):

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:/usr/x86_64-w64-mingw32/sys-root/mingw/bin/:$PATH
export CAMLP4LIB=C:/OCaml/lib/camlp4

Run source ~/.bashrc in any (open) terminals to get the new (proper) environment.

Install depext-cygwinports

opam install depext-cygwinports

Theoretically not needed now that the x86_64-mingw32-* packages are in the mainstream Cygwin repo, but the special fixes in fdopen's repository won't kick in until this is installed.

Install a bunch of opam packages

Run opam install zarith batteries stdint fileutils sqlite3 yojson.

If opam fails to install a package (e.g. sqlite3), try again opam install sqlite3.

Troubleshooting

  • If OPAM complains that it cannot install a file into ~/.opam/system/bin because it already exists, for instance:

      # install: cannot create regular file '/cygdrive/d/cygwin/home/protz/.opam/system/bin/bdump': File exists
    

    then you're hitting https://github.com/ocaml/opam/issues/2313 and you need to remove locally the package.install file. In this case:

      rm ~/.opam/repo/default/packages/biniou/biniou.1.0.12/files/biniou.install
    
  • If that still doesn't work, a very subtle solution involves running in a separate terminal: protz@Joprotze-Z420:~/.opam/system/bin $ while true; do \rm bdump.exe; done

  • If OPAM complains that the system dependency on GMP cannot be found, and if you're positive that the cygwin package mingw64-x86_64-gmp is installed, then open the Cygwin terminal and fake the installation of OPAM package conf-gmp:

      $ opam install --fake conf-gmp
    
  • If, building miTLS, you get:

      ** Cannot resolve symbols for C:/cygwin/home/protz/.opam/system/lib/sqlite3\libsqlite3_stubs.a(sqlite3_stubs.o):
       sqlite3_enable_load_extension
    

    then:

      opam remove sqlite3
      export SQLITE3_DISABLE_LOADABLE_EXTENSIONS=1
      opam install sqlite3
    
  • OPAM pretends to call curl but really it's only calling wget; make sure wget is installed

  • make sure your OCaml executable is the right one (where ocaml)

  • make sure OCAMLLIB is properly set using a Windows-style path (e.g. C:\OCaml\lib). This is known to cause opam install sqlite3 to fail.

  • check the output of ocamlopt -config (should contain native_c_compiler: x86_64-w64-mingw32-gcc -O -mms-bitfields -Wall -Wno-unused)

Package-specific hints:

  • Installing ppx_deriving and friends: you need these two commands:

      protz@Joprotze-Z420:~/.opam/system/lib $ find . -iname '*.cmxs' -exec chmod a+x {} \;
      protz@Joprotze-Z420:~/.opam/system/lib/ppx_deriving $ cp ppx_deriving ppx_deriving.exe
    
  • Installing ctypes: first, you need the libffi library installed in Cygwin, but in a MinGW variant. So, you must start cygwin-setup-x86_64.exe and choose installation of a package named: mingw64-x86_64-libffi (not simple "libffi"). After installing it, you can verify by typing in Cygwin Terminal: pkg-config --list-all (it should show "libffi").

    FIXME: trying to load ctypes in utop unfortunately fails for me for now (full transcript here):

      utop # #require "ctypes.foreign";;
      Error: Reference to undefined global `Ctypes_closure_properties'
    

    There's some comment that "a static version of libffi" might work, but I don't know yet how to do this for use in utop.

  • Installing and running utop: After successfully installing through Cygwin Terminal with opam install utop (note: you'll need the hint above in "Troubleshooting" about removing .install files), you will see a message:

      =-=- utop.1.19.3 installed successfully -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
      => UTop does not work inside a cygwin terminal (mintty, urxvt,...). Use
         cmd.exe, ConsoleZ or a similar
          terminal emulator.
    

    so, you can't run utop in Cygwin Terminal, but you must do this in normal cmd.exe window. For this to work correctly, you must set your PATH properly. To make it slightly easier, while still in Cygwin Terminal, type the following:

      cd $HOME && cmd /c start cmd
    

    It should start a new cmd.exe window, with Cygwin environment variables already set (specifically, $HOME). There, you should be able to start utop by typing the following commands:

      set PATH=%HOME%\.opam\system\bin;%PATH%
      set PATH=%HOME%\.opam\system\lib\stublibs;%PATH%
      utop
    
  • Merlin works very well but does not install with my current installer.

I ran:

protz@Joprotze-Z420:~/Code/merlin (master) $ ./configure --prefix ~/.opam/system && make && make install

then I have in my ~/.vimrc the following, to make sure that ocamlmerlin can be found in all cases (Cygwin vs non-Cygwin on Windows, but also other setups):

execute "silent !which cygpath > /dev/null 2>&1"
if v:shell_error == "0"
  let g:opamshare = system('cygpath $(opam config var share) | tr -d ''[:space:]''')
else
  let g:opamshare = substitute(system('opam config var share'),'\n$','','''')
endif
execute "set rtp+=" . g:opamshare . "/merlin/vim"
execute "set rtp+=" . g:opamshare . "/ocamlmerlin/vim"

Misc

opam depext foobar should now be able to install the right Cygwin packages for your toolchain

Every command in cygwin is extremely slow?

See the solution here: https://gist.github.com/k-takata/9b8d143f0f3fef5abdab#solution-2-disable-db-in-etcnsswitchconf