Here is a simple ocaml file, just meant to get me to understand how to load a program that uses the Batteries library into the ocamltop.
batteryassault.ml
open Batteries
let main = print_string "hello, world ... powered on"
I compile this to bytecode with
ocamlfind ocamlc -package batteries -linkpkg batteryassault.ml
Resulting in batteryassault.cmo and batteryassault.cmi, and no errors nor warnings. Then, I start the battery-powered ocamltop with
rlwrap ocamlfind batteries/ocaml
Finally, to load the file in ocamltop:
#load "batteryassault.cmo" ;;
And then we get an error.
The files batteryassault.cmo and /usr/lib/ocaml/batteries/batteries.cma disagree over interface Batteries
I think what could be going on is that Ubuntu installs batteries 2.2.1, but for some reason (installing merlin?) I have batteries 2.3.1 installed in my opam folder, and moreover, when starting the ocamltop with batteries as above, it indicates that ocamltop is using the 2.2.1 version. Further, compiling with
ocamlfind ocamlc -package batteries -linkpkg batteryassault.ml -verbose
I find that ocamlc is definitely using the library in opam, i.e. the 2.3.1 version.
So my question is: what is the/is there a workaround?