Installing ocaml-windows error

I’m having trouble setting up a windows cross compiler. I’m getting stuck on installing ocaml-windows32 on ubuntu 16.04.

Here is a Dockerfile that outlines the steps I have taken:

FROM ubuntu:16.04

RUN apt-get update
RUN apt-get install -y \
  ocaml \
  opam \
  gcc-mingw-w64-i686 \
  gcc-mingw-w64-x86-64 \
  m4 \
  gcc-multilib

RUN opam init
RUN opam repository add windows git://github.com/ocaml-cross/opam-cross-windows
RUN opam switch 4.06.1+32bit
RUN eval `opam config env`
RUN opam pin add topkg https://github.com/whitequark/topkg.git
RUN opam install conf-flambda-windows
RUN opam install ocaml-windows

CMD ["/bin/bash"]

This eventually fails with the following output:

=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[conf-gcc-windows32: sh ${TOOLPREF32-i686-w64-mingw32-}gcc --version] Command started
[conf-gcc-windows32: sh echo "prefix: \"${TOOLPREF32-i686-w64-mingw32-}\"" >conf-gcc-windows32.config] Command started
-> installed conf-gcc-windows32.1
[conf-gcc-windows: ./generate-config.sh i686-w64-mingw32-] Command started
[flexdll-windows: touch Compat.ml] Command started
-> installed conf-gcc-windows.1
[flexdll-windows: i686-w64-mingw32-gcc flexdll.c] Command started
[flexdll-windows: i686-w64-mingw32-gcc flexdll_initer.c] Command started
[flexdll-windows: ocamlopt version.ml] Command started
-> installed flexdll-windows.0.37
[ocaml-windows32: ./build.sh] Command started
[ocaml-windows32: ./install.sh] Command started
[ERROR] The compilation of ocaml-windows32 failed at "./install.sh
        /root/.opam/4.06.1+32bit".
[ocaml-windows32: ./remove.sh] Command started

#=== ERROR while installing ocaml-windows32.4.06.1 ============================#
# opam-version         1.2.2
# os                   linux
# command              ./install.sh /root/.opam/4.06.1+32bit
# path                 /root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1
# compiler             4.06.1+32bit
# exit-code            1
# env-file             /root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1/ocaml-windows32-7-90b366.env
# stdout-file          /root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1/ocaml-windows32-7-90b366.out
# stderr-file          /root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1/ocaml-windows32-7-90b366.err
### stdout ###
# if test -f ocamlopt.opt ; then make installoptopt; else \
# [...]
# fi
# make -C tools installopt
# make[2]: Entering directory '/root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1/tools'
# cp -- profiling.cmx profiling.o "/root/.opam/4.06.1+32bit/windows-sysroot/lib/ocaml"
# make[2]: Leaving directory '/root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1/tools'
# if test -f ocamlopt.opt -a -f flexdll/flexlink.opt ; then \
#   cp -f flexdll/flexlink.opt "/root/.opam/4.06.1+32bit/windows-sysroot/bin/flexlink.exe" ; \
# fi
# make[1]: Leaving directory '/root/.opam/4.06.1+32bit/build/ocaml-windows32.4.06.1'
### stderr ###
# cp: cannot stat '/root/.opam/4.06.1+32bit/lib/graphics': No such file or directory



=-=- Error report -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
The following actions were aborted
  - install ocaml-windows 4.06.1
The following actions failed
  - install ocaml-windows32 4.06.1
The following changes have been performed
  - install conf-gcc-windows   1   
  - install conf-gcc-windows32 1   
  - install flexdll-windows    0.37

The former state can be restored with:
    opam switch import
"~/.opam/4.06.1+32bit/backup/state-20180626225244.export"
The command '/bin/sh -c opam install ocaml-windows' returned a non-zero code: 4

This fails the same way in my none docker env. Not entirely sure how to fix this.

Anyone have any ideas?

It seems you need graphics package (which comes with the base ocaml system, but requires X11 libraries). Do you have X11 installed?

Thanks for the x11 hint!

I was able to get things working with a 64 bit compiler, but not a 32 bit. Fails with the missing graphics error above.

Updated Dockerfile. There were some env issues but fixing those didn’t seem to do much :slight_smile:

FROM ubuntu:16.04

ENV DEBIAN_FRONTEND noninteractive

RUN apt-get update
RUN apt-get install -y \
gcc-mingw-w64-i686 \
gcc-mingw-w64-x86-64 \
gcc-multilib \
m4 \
xorg \
xorg-dev \
libx11-dev

RUN apt-get install -y \
ocaml \
opam

RUN opam init
RUN opam repository add windows git://github.com/ocaml-cross/opam-cross-windows
RUN opam switch 4.06.1+32bit && \
eval `opam config env` && \
opam update -y && opam upgrade -y && \
opam pin add topkg https://github.com/whitequark/topkg.git && \
opam install conf-flambda-windows && \
opam install ocaml-windows && \
opam pin


RUN echo 'let () = print_endline "Hello, world!"' > helloworld.ml

RUN opam switch 4.06.1+32bit && \
eval `opam config env` && \
ocamlfind -toolchain windows ocamlopt helloworld.ml -o helloworld.native

CMD ["/bin/bash"]
1 Like

Make sure your computer has enough space, all your device/graphics drivers are upto date.

Regards,
Adrian Gates
System Admin - Apps4Rent