> So I am investigating packing my nice Ocaml code into a library and > writing C bindings so that I can talk to it. [...] > In particular, I have found > none that cover how to obtain pointers to OCaml function return values > that are not strings or ints, how to store them in C-land, and how to pass > them back to Ocaml as parameters. You have two choices: copy the contents of the OCaml data structure to a C data structure, e.g. an OCaml tuple or record of ints can be copied to a C struct, field by field; or, treat the OCaml value as an opaque type on C's side. The code you posted attempts to do the second approach, but you cannot just take a Caml "value" and give it to arbitrary C code: the Caml GC will lose track of the value and reclaim it (or copy it elsewhere) at the first opportunity. Instead, you need to wrap the Caml value in a C memory block and register it with the GC using caml_register_global_root. Then, an explicit free function must be provided in the C interface to unregister with the GC and to free the wrapper. See the attached modification of your ht_wrap.c example. It should put you on the right tracks. > 5. And this is how I am attempting to compile it. Note that error I'm > getting here is in link. If I add "-lm" it gets less noisy but still is > mad at me. Why am I having to add math library? Because the Caml runtime system needs it. As Dmitry wrote, the simplest way to build your example is: ocamlopt -output-obj -o ht_lib.o ht.ml ocamlopt -c ht_wrap.c gcc -o htt ht_test.c ht_lib.o ht_wrap.o -L`ocamlopt -where` -lasmrun -lcurses -lm Hope this helps, - Xavier Leroy