Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
Building with OCamlMkLib
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Stefano Zacchiroli <zack@u...>
Subject: Re: [Caml-list] Building with OCamlMkLib
On Tue, Jan 20, 2009 at 05:03:55PM +0000, John Whitington wrote:
> I'm building a Plain C interface to our PDF libraries, but am
> stuck. The idea is to build a library with Ocamlmklib containing the
> C wrapper around the ocaml code.

I've been working on a similar task these days.

As Alain pointed out you were missing the -output-obj step. The actual
rules I'm using to build the (static) library which is my current
output are something like the following (Makefile excerpt):

  libcudf.a: cudf-caml.o cudf.o
	  cp $(OCAML_LIBDIR)/libcamlrun.a $@
	  ar r $@ $^

  cudf-caml.o: ../_build/cudf.cma ../_build/cudf_c.cmo
	  ocamlfind ocamlc -linkpkg -output-obj -o $@ $^

where the stuff coming from _build/ is the output of the OCaml-only
part of the library, and libcudf.a is the final C library to be
delivered to C programmers.

The real code from which this comes from is available at [1].

Note that the C programmers will then need to link in a peculiar way,
here are my current instructions for them:

  cc -o test test.c `pkg-config --cflags cudf` `pkg-config --cflags cudf`

Which expands to something schematic like:

  cc -o test test.c <INCLUDE PATHS> <LIB PATHS> -lcudf -lm -ldl -lunix -lncurses <OTHER -l FOR EXTERNAL LIBS>

The glitch here is that test.c, which contains the invocation to
caml_startup, must appear *before* -lcamlrun, as AFAICT it needs to
override the main() defined there. If you try to put it at the end of
the linking line, linking will fail.



Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{,,} -<>-
Dietro un grande uomo c'è ..|  .  |. Et ne m'en veux pas si je te tutoie
sempre uno zaino ...........| ..: |.... Je dis tu à tous ceux que j'aime