62

I'm trying to get an OCaml environment set up, and I've followed the instructions from appendix A of the Real World OCaml beta. I set up opam, and installed a version of OCaml with the command

$ opam switch 4.01.0dev+trunk

which passed fine. I then did an

$ eval `opam config env`

to pull in the changes. I'm running the correct top level, as

$ which ocaml

outputs

/home/bryan/.opam/4.01.0dev+trunk/bin/ocaml

I installed the Core package from Jane street, with the command

$ opam install core

Both ocamlfind and opam search show that the package was installed correctly. However when I try to open it either from the repl or in a file, I get the error 'unbound module Core'. e.g.

$ ocaml
# open Core;;
Error: Unbound module Core

Is there something I'm missing here? Why can't OCaml find my installed module?

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
bstamour
  • 7,746
  • 1
  • 26
  • 39

2 Answers2

73

So I jumped the gun a bit. I forgot to add some items to my ~/.ocamlinit file. Specifically I forgot to add

#use "topfind"
#camlp4o
#thread
#require "core.top"
#require "core.syntax"

as mentioned in Chapter 1. D'oh!

bstamour
  • 7,746
  • 1
  • 26
  • 39
  • 8
    Manually adding lines to config files? Isn't that a bit archaic? – kristianp Mar 19 '14 at 09:04
  • 9
    Yes, you're right. I was just a little frustrated at the amount of setup required to get started with Opam, utop and the Core library. – kristianp Mar 20 '14 at 01:39
  • @kristianp it is a bit of slog. Not the worst I've had so far, but not super straightforward either. – Shon Oct 27 '14 at 07:10
  • I have the same problem, but I’ve put those lines in the `.ocamlinit`, and the error keeps raising. :-( – Arĥimedeς ℳontegasppα ℭacilhας Feb 07 '16 at 13:18
  • 1
    Indeed my problem is quite different: running `ocaml`, `open Core.Std;;` works fine, but inside a script, it cannot be compiled – raises `Unbound module Core`. – Arĥimedeς ℳontegasppα ℭacilhας Feb 07 '16 at 13:22
  • 1
    Let it go… finally I realise what’s wrong: I was trying to compile using `ocamlc`, when the right way is by using `corebuild`. Sorry for bothering. – Arĥimedeς ℳontegasppα ℭacilhας Feb 07 '16 at 13:27
  • 1
    Now in [the wiki](https://github.com/realworldocaml/book/wiki/Installation-Instructions), but still a useful answer. – cdunn2001 Jun 23 '16 at 03:39
  • 16
    Requiring to edit a textfile as part of an installation procedure to achieve something that apparently everybody wants seems archaic to me as well. Or is the Core library so exquisite and exceptional? I just installed ocaml and I have no clue what the five lines added to ~/.ocamlinit mean. After just being asked by a script "[2/4] Do you want to update your ~/.ocamlinit?", I wonder why these five lines are not added as part of some installation script. – Günter Rote Aug 22 '16 at 21:37
  • Just comment as supplement to this answer, here's a [video](https://asciinema.org/a/36250) showing how to install OPAM on ubuntu 14.04 and run `open Core.Std;;` in utop. I tested as the video goes on my env also. I'm using Mac OSX 10.10.5. – Old Panda Aug 14 '17 at 00:46
  • "core.syntax" is deprecated as of 2022 use "ppx_jane" instead. Follow this (dev.realworldocaml.org/install.html) for more details – Seth P Oct 06 '22 at 13:16
12

Please follow the steps in the Real World OCaml Wiki - Installation Instructions.

Under Setting up and using utop, the instructions state that you should add:

#use "topfind";;
#thread;;
#camlp4o;;
#require "core.top";;
#require "core.syntax";;

to your ~/.ocamlinit file.

hayesgm
  • 8,678
  • 1
  • 38
  • 40