Help getting started: compiling sum.ml from RWO Chapter 1


#1

Following along in Chapter 1 of RWO, I get to the final program:

sum.ml

open Core
   
let rec read_and_accumulate accum =
  let line = In_channel.input_line In_channel.stdin in
  match line with
  | None -> accum
  | Some x -> read_and_accumulate ( accum +. Float.of_string x )

let () =
  printf "Total: %F\n" (read_and_accumulate 0.)

I have Core successfully installed via opam, but when I try to compile it using corebuild I get:

corebuild sum.native
ocamlfind ocamlopt -linkpkg -g -thread -package core sum.cmx -o sum.native
+ ocamlfind ocamlopt -linkpkg -g -thread -package core sum.cmx -o sum.native
File "_none_", line 1:
Error: No implementations provided for the following modules:
         Stdio__ referenced from sum.cmx
         Core_kernel__ referenced from sum.cmx
Command exited with code 2.
Hint: Recursive traversal of subdirectories was not enabled for this build,
  as the working directory does not look like an ocamlbuild project (no
  '_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories,
  you should add the option "-r" or create an empty '_tags' file.
  
  To enable recursive traversal for some subdirectories only, you can use the
  following '_tags' file:
  
      true: -traverse
      <dir1> or <dir2>: traverse

Any ideas on how to proceed? I am running OCaml v4.06.1 with Core v0.10.0 on RHEL 7.4 with opam v1.2.2.


#2

This is due to a regression in jbuilder beta18. Pinning Jbuilder to beta17 should fix the issue.

BTW, corebuild is no longer expected to work. I think RWO is getting updated. The recommended way is to write a jbuild file as follow:

(executable
 ((name sum)
  (libraries (core))))

and build and run the executable with:

$ jbuilder exec ./sum.exe

#3

That worked, thanks!

Pinning jbuilder was done by:

opam pin add jbuilder 1.0+beta17