stumped
stumped

Reputation: 3293

Unbound module Yojson.Basic.Util

I try opening Yojson.Basic.Util in one of my files and keep getting an unbound module error. I've tried several different things and can't seem to figure out what's wrong

I have this in my .ocamlinit:

#require "yojson";;
#require "ANSITerminal";;

and this in my makefile:

test:
    ocamlbuild -pkg yojson, oUnit test.byte && ./test.byte

play:
    ocamlbuild -pkgs oUnit,yojson,str,ANSITerminal main.byte && ./main.byte

check:
    bash checkenv.sh

clean:
    ocamlbuild -clean

Typing make produces this error:

ocamlbuild -pkg yojson, oUnit test.byte && ./test.byte
ocamlfind: Package `yojson,' not found
Cannot run Ocamlfind.
make: *** [test] Error 2

Changing the makefile to:

test:
    ocamlbuild -use-ocamlfind -pkg yojson, oUnit test.byte && ./test.byte

play:
    ocamlbuild -pkgs oUnit,yojson,str,ANSITerminal main.byte && ./main.byte

check:
    bash checkenv.sh

clean:
    ocamlbuild -clean

I type in make and it gives me this error:

ocamlbuild -use-ocamlfind -pkg yojson, oUnit test.byte && ./test.byte
Solver failed:
  Ocamlbuild knows of no rules that apply to a target named oUnit. This can happen if you ask Ocamlbuild to build a target with the wrong extension (e.g. .opt instead of .native) or if the source files live in directories that have not been specified as include directories.
Compilation unsuccessful after building 0 targets (0 cached) in 00:00:00.
make: *** [test] Error 6

Upvotes: 1

Views: 1109

Answers (1)

Reimer Behrends
Reimer Behrends

Reputation: 8730

There is a difference between the -pkg and -pkgs option for ocamlbuild. The -pkg option takes exactly one package name. The -pkgs option takes a list of comma-separated package names (there can be optional spaces before and after the commas, but then you have to quote the argument).

In your example, you use -pkg, but with a comma-separated list of arguments, and that list has a space, so it would have to be quoted. Using -pkgs yojson,oUnit should fix the issue.

Upvotes: 2

Related Questions