Reputation:
I have a file main.ml
that uses some package that makes the command ocaml main.ml
fail and report this error:
Error: Unbound module X
And the only solution I've found so far is to run:
ocamlbuild main.native -use-ocamlfind -package X
./main.native
But this compiles the file. Is there a way to just run the regular ocaml interpreter (ocaml main.ml
) with some additional flags to make it find the package?
Upvotes: 1
Views: 266
Reputation: 4431
You can also query the path of your package to ocamlfind :
ocamlfind query package_X
That will return the path of your package : /path_to/packageX
And then :
ocaml main.ml -I /path_to/packageX
Upvotes: 2
Reputation: 18902
The easiest way is probably to use topfind and add #require "core"
at the top of your file. If you want to avoid adding toplevel directives in your file, you can use ocamlfind query -i-format -r
to compute the required include directories:
ocaml $(ocamlfind query -i-format -r core) main.ml
Upvotes: 2
Reputation: 1965
You can put at the beginning of your file some top-level directives which find and load needed modules. For example, when I want to use Core
library in my script I insert:
#use "topfind";;
#thread;;
#require "core";;
open Core.Std
(* Code of my script *)
To use topfind
package ocamlfind
has to be installed (opam install ocamlfind
)
Upvotes: 2