Friday, February 6, 2015

Solving issues with installing the "Real World OCaml" prerequisite libraries under Mac OS X

    I’ve run into some troubles installing the «Real World Ocaml» prerequisites under Mac OS X Yosemite. The installation process is described on the books’ wiki here. I've found little help by googling the error messages, which possibly means they could be very specific to my installation. So I've decided to share my experience in case someone runs into similar issues.
    At one point, the instruction advises you to install some libraries that are used throughout the book, by issuing the following command:
opam install \
   async yojson core_extended core_bench \
   cohttp async_graphics cryptokit menhir

    At first I’ve failed to install the cohttp and async_graphics packages. Possibly that was because I already had objective-caml installed, and my process of installation deviated a bit from the one prescribed by the instruction.
    The cohttp package depends on ctypes package, which was failing with the following error:
# fatal error: 'ffi.h' file not found
# #include <ffi.h>

    To solve it, just install libffi and add it to LDFLAGS environment variable for the time of build:
brew install libffi
export LDFLAGS=-L/usr/local/opt/libffi/lib
opam install cohttp

    If during the installation of async_graphics module you receive an error:
# Error: Unbound module Graphics

    That probably means you’ve installed objective-caml without the Graphics module, which may be verified by the listing:
ls /usr/local/opt/objective-caml/lib/ocaml/graphics*

    If the listing is empty, then you should reinstall objective-caml with graphics:
brew uninstall objective-caml
brew install objective-caml --with-x11

Now the process of installing the async_graphics package should work just fine:
opam install async_graphics

1 comment:

  1. Thanks for posting these notes. Saved me a lot of frustration on the async_graphics problem.