I’m experimenting with compiler-libs.toplevel and findlib for some project, and I’m puzzled by the following problem. The following code loads the plplot library and calls a function from the library:
let eval_string s =
let lexbuf = Lexing.from_string s in
let phrase = !Toploop.parse_toplevel_phrase lexbuf in
let success = Toploop.execute_phrase true Format.err_formatter phrase in
ignore success
let () =
Toploop.initialize_toplevel_env () ;
Topdirs.dir_use Format.std_formatter "topfind";
eval_string {|#require "plplot";;|};
eval_string "Plplot.plinit ();;"
It works just the way I expect it to. Now when I replace the second item by:
The external function `camlidl_plplot_core_c_plinit' is not available
Since both versions work when I try to load a pure-OCaml library (like, say, containers), I suspect the problem comes from the C part (plplot is a binding). A further indication is that with the first version, findlib prints:
/home/pveber/.opam/4.11.1/lib/plplot: added to search path
/home/pveber/.opam/4.11.1/lib/plplot/plplot.cma: loaded
while the second version only prints the first of the two lines. When I check the code registered for the #require directive though, I can’t anything see relevant besides the call to Topfind.load_deeply. Would anyone have an idea what I should set to make it work?
is the bit I was missing more specifically in my code. I should have the comments in Topfind more carefully:
* The [Topfind] module needs some initialization, in particular the
* [predicates] variable needs to be
* set, and the packages already compiled into the toploop needs to be
* declared by the [don't_load]
* function.
Thanks a lot! That one I could have stayed hopelessly looking for it for a long, long time. But of course it makes a lot of sense: not being able to find symbols meant I had a linking issue. Now it works perfectly, thanks a bunch!