# Installing ocaml-windows error

**URL:** <https://discuss.ocaml.org/t/installing-ocaml-windows-error/2345>\
**Category:** Learning\
**Tags:** build\
**Created:** [July 26, 2018, 11:01pm UTC](https://discuss.ocaml.org/t/installing-ocaml-windows-error/2345 "2018-07-26T23:01:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nerdyworm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nerdyworm/32/1105_2.png) [@nerdyworm](https://discuss.ocaml.org/u/nerdyworm)\
**Post date:** [July 26, 2018, 11:01pm UTC](https://discuss.ocaml.org/t/installing-ocaml-windows-error/2345/1 "2018-07-26T23:01:41Z")

</div>

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:

```auto
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:

```auto
=-=- 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?

---

<div class="post-metadata">

**Author:** ![Freyr666](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/freyr666/32/591_2.png) [@Freyr666](https://discuss.ocaml.org/u/Freyr666)\
**Post date:** [July 27, 2018, 7:53am UTC](https://discuss.ocaml.org/t/installing-ocaml-windows-error/2345/2 "2018-07-27T07:53:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nerdyworm](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/nerdyworm/32/1105_2.png) [@nerdyworm](https://discuss.ocaml.org/u/nerdyworm)\
**Post date:** [July 31, 2018, 2:28pm UTC](https://discuss.ocaml.org/t/installing-ocaml-windows-error/2345/3 "2018-07-31T14:28:20Z")

</div>

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 🙂

```auto
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"]

```

---

<div class="post-metadata">

**Author:** ![AdrianG001](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@AdrianG001](https://discuss.ocaml.org/u/AdrianG001)\
**Post date:** [August 6, 2018, 3:25pm UTC](https://discuss.ocaml.org/t/installing-ocaml-windows-error/2345/4 "2018-08-06T15:25:00Z")

</div>

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

Regards,  
Adrian Gates  
System Admin - [Apps4Rent](https://www.apps4rent.com)
