SaxSalute
SaxSalute

Reputation: 359

Using ocamlmktop with ocamlbuild

I have a project that builds successfully using ocamlbuild. However, I would also like an easy way to interact with the project's individual functions from different modules via the toplevel but my attempts at using ocamlmktop haven't worked out as I'd like. I've found that unless I manually put the .cmi files in the active directory, I get an "Unbound module" error. The command I'm currently using to build is:

ocamlfind ocamlmktop -I _build -o my_ocaml -linkpkg -package str module1.cmo module2.cmo

Is there a better, less hacky way to get the toplevel to work in this project structure without moving cmi files out of the _build directory?

Edit: I've figured out that I can get it to load the types and modules if I run the toplevel as

./my_ocaml -I _build

But this still seems hacky. Is there a way to bake the search path or cmi files in perhaps?

Edit 2: I think the solution to my problem may actually be not to compile a custom toplevel at all given this restriction about interface files. I have instead added load directives to my .ocamlinit to use the modules. If anybody has better ideas to solve this, I'd greatly appreciate it.

Upvotes: 2

Views: 266

Answers (1)

gasche
gasche

Reputation: 31459

You can build a toplevel by listing the module names you want in a my_ocaml.mltop file:

Module1
Module2
subdir/Module3

Then building the target my_ocaml.top will call ocamlmktop in the expected way, and you can run the resulting my_ocaml.top toplevel.

This does not change the way that you need to add _build to the include path for the type-checker to be able to find the .cmi files. You can do this when you invoke the toplevel by passing the command-line arguments -I _build, or from the toplevel with #dir "_build";; -- the last command can also be put in your .ocamlinit if you prefer.

Upvotes: 2

Related Questions