Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Building C/Ocaml libraries

1 view
Skip to first unread message

Kevin

unread,
Oct 30, 2006, 10:36:55 AM10/30/06
to
Hi there,
I'm quite new to OCaml and am having some trouble building my own
libraries.

Here's roughly what I have:

lib.c: contains function "myCfunction"
lib.ml: external myfunction : string -> int = myCfunction, class
myclass
test.ml: uses Lib.myclass and Lib.myfunction

How do I build lib.c and lib.ml into lib.cmxa, and then compile it with
test.ml? I've been trying for a few hours and I get various different
errors. One example:

$ ocamlopt -o test ocaml-lib.cmxa lib.ml lib.c test.ml -cclib -lC-lib

lib.o: In function `myCfunction':
lib.c:(.text+0x0): multiple definition of `myCfunction'
lib.o:lib.c:(.text+0x0): first defined here
/tmp/camlstartupd80bc7.o: In function `caml_program':
: undefined reference to `camlMl3d__entry'
/tmp/camlstartupd80bc7.o: In function `caml_globals':
: undefined reference to `camlMl3d'

...

collect2: ld returned 1 exit status
Error during linking

Tim

unread,
Oct 31, 2006, 9:46:47 PM10/31/06
to
Try renaming your implementation file:

ocamlopt impl_lib.c lib.ml test.ml -o test

works, but

ocamlopt lib.c lib.ml test.ml -o test

does not (at least on Linux).

If you want to build the .cmxa as a separate step:

ocamlopt impl_lib.c lib.ml -a -o lib.cmxa
ocamlopt lib.cmxa test.ml -o test

tim

0 new messages