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 mymixed_module.ml module uses some “external” C functions defined in mycode.c .

If I do #use"mymixed_module.ml" 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 ?

Hi,

You must use ocamlmklib:

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

It creates mylib.cma, dllmylib.so 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.