0

I have created my ~/.ocamlinit as follows

let interactive = !Sys.interactive;;
Sys.interactive := false;; (*Pretend to be in non-interactive mode*)
#use "topfind";;
Sys.interactive := interactive;; (*Return to regular interactive mode*)

Toploop.use_silently Format.err_formatter (Filename.concat (Findlib.package_directory "batteries") "battop.ml");;

When I type ocaml at command line, I get the following error:

$ ocaml
        Objective Caml version 3.12.1

Cannot find file topfind.
File ".ocamlinit", line 6, characters 60-85:
Error: Unbound module Findlib
# 

What is causing this issue and how should I go about for fixing this issue?

(I am on Debian Wheezy)

Edit: I have set an alias for ocaml:

alias ocaml='rlwrap -H /home/nanda/.ocaml_history -D 2 -i -s 10000 ocaml'
Animesh
  • 4,926
  • 14
  • 68
  • 110
  • It might be helpful to first check if `#use "topfind";;` works when the toploop has been started without your `.ocamlinit`. – dkim Sep 26 '12 at 21:16
  • @dkim: Strange! I checked and that does not work either. – Animesh Sep 26 '12 at 21:17
  • Did you install the `ocaml-findlib` package? http://packages.debian.org/wheezy/ocaml-findlib – dkim Sep 26 '12 at 21:20
  • Yes I installed it, sorry to not have mentioned it. I just added a statement to print "TESTING" in the .ocamlinit and I could see it above the "cannot find the file topfind" part. – Animesh Sep 26 '12 at 21:23
  • How about `libfindlib-ocaml-dev`? – dkim Sep 26 '12 at 21:29
  • 1
    That did the trick!! Thank you so much. I am not sure why a dev package would be required. Any insight in this regard? – Animesh Sep 26 '12 at 21:35
  • 1
    A library usually consists of two packages, one for runtime and another for development files. [What do the *-dev packages in the Linux package repositories actually contain?](http://stackoverflow.com/q/1157192/234658) – dkim Sep 26 '12 at 21:41
  • In this case, the `/usr/lib/ocaml/topfind` file that the `#use "topfind";;` directive searches for turns out to be included in the `libfindlib-ocaml-dev` package. – dkim Sep 26 '12 at 22:01
  • I ought to search for topfind using apt-file before, but somehow it didnt register to me that topfind, a module, is actually a file. Thanks for all the help. – Animesh Sep 26 '12 at 22:47

1 Answers1

2

With due thanks to dkim, I would post the solution that worked for me. Hope this helps someone else.

Ocaml Batteries Installation Process

To be able to work with the ocaml-batteries-included, I followed this process:

sudo apt-get install ocaml ocaml-batteries-included ocaml-doc ledit rlwrap

rlwrap or ledit is needed to add readline support for OCaml toploop.

Added an alias in .bashrc, to save the commands entered in the ocaml toploop.

 alias ocaml='rlwrap -H /home/nanda/.ocaml_history -D 2 -i -s 10000 ocaml'

-H specifies history file name
-D ignores duplicates
-i case insensitive
-s limits the number of commands stored in this file

As mentioned in the comments, I was receiving this error when trying to invoke the ocaml interpreter.

$ ocaml
        Objective Caml version 3.12.1

Cannot find file topfind.
File ".ocamlinit", line 6, characters 60-85:
Error: Unbound module Findlib
# 

I received this error because ocaml-findlib package was not properly installed. I have mamaged to solve this by installing the libfindlib-ocaml-dev package:

sudo apt-get install libfindlib-ocaml-dev

For some people, the issue is solved when findlib package is installed from sources as mentioned here

Some more helpful links:

  1. http://mirror.ocamlcore.org/wiki.cocan.org/tips_for_using_the_ocaml_toplevel.html
  2. http://projects.camlcity.org/projects/dl/findlib-1.2.1/doc/guide-html/quickstart.html
  3. http://www.donadeo.net/post/2010/installing-batteries
Animesh
  • 4,926
  • 14
  • 68
  • 110