How to load C object files in the toplevel (ocaml or utop)?

I have a myccode.c file of C code which, compiled, produces a myccode.o object file.
The module uses some “external” C functions defined in mycode.c .

If I do #use"" in my toplevel, I get error message
“The external function `…’ is not available”.

So, how do I tell the toplevel to “load” the myccode.o file ? I noticed
that #load"myccode.o" does not work. Perhaps I should add myccode.o as an argument
when I initially launch ocaml or utop ?


You must use ocamlmklib:

ocamlc mycode.c
ocamlmklib -o mylib mymixed_module.cmo mycode.o

It creates mylib.cma, and libmylib.a.

You can now #load "mylib.cma"

Doesn’t work for me. I did exactly what you suggested, and everything goes as you say, except for the very last step : when I do `#load “mylib.cma” I get the exact same error message, external function … is not available.

Update/correction : it does work after I re-did everything from scratch and restarted the toplevel.