Cannot compile sample file with corebuild installed with asdf

I’m (re)-learning OCaml, and I hit a snag while trying to compile a simple program:

open Core

let print_current_dir_files () = 
  Sys.readdir "."
  |> Array.to_list
  |> String.concat ~sep:"\n\t"
  |> printf "Files: \n\t%s\n"

let () =
  print_current_dir_files()

This code works in coretop, but when I try to compile it, that’s what I get:

$ corebuild src/hello_world.native

+ ocamlfind ocamlopt -linkpkg -g -thread -package base -package core_kernel -package core -I src src/hello_world.cmx -o src/hello_world.native
File "_none_", line 1:
Error: No implementations provided for the following modules:
         Core_kernel__ referenced from src/hello_world.cmx
         Core__ referenced from src/hello_world.cmx
Command exited with code 2.
Compilation unsuccessful after building 4 targets (0 cached) in 00:00:00.

I tried adding -pkg flags, creating _tags, running it with manual linking via ocamlbuild, but nothing works.

I have Merlin and utop working without problem with Core. OCaml 4.06.1 is installed with asdf OCaml plugin. Some more debug output:

$ ocamlfind query core
/home/lakret/.asdf/installs/ocaml/4.06.1/4.06.1/lib/core

$ ocamlfind query core_kernel
/home/lakret/.asdf/installs/ocaml/4.06.1/4.06.1/lib/core_kernel

Compiling sample files without Core dependency is working fine.

Any ideas? Maybe I’m missing something?

I think dune(formerly jbuilder) is by far the best build tool for ocaml these days. https://github.com/ocaml/dune. For your sample file you can follow these steps:

  1. Create a jbuild file.
$cat jbuild
(jbuild_version 1)

(executable
 ((name hello)
  (libraries (core))))
  1. Build with jbuilder - jbuilder build hello.exe
  2. Execute - jbuilder exec -- ./hello.exe
    prints the following in my temp dir
Files: 
	hello.ml
	jbuild
	_build
	.merlin
1 Like

I think it is related to this issue (suggested solutions in the linked comment): ANN: dune (jbuilder) 1.0+beta18