<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE message PUBLIC
  "-//MLarc//DTD MLarc output files//EN"
  "../../mlarc.dtd"[
  <!ATTLIST message
    listname CDATA #REQUIRED
    title CDATA #REQUIRED
  >
]>

  <?xml-stylesheet href="../../mlarc.xsl" type="text/xsl"?>


<message 
  url="2009/01/2a7886bfc158bad05addcad2991a2059"
  from="Stefano Zacchiroli &lt;zack@u...&gt;"
  author="Stefano Zacchiroli"
  date="2009-01-21T14:43:29"
  subject="Re: [Caml-list] Building with OCamlMkLib"
  prev="2009/01/0fbff864e2edb7059ab802560278f082"
  next="2009/01/ea82fc74b055cf6591555ecac3085480"
  prev-in-thread="2009/01/7b91d248f034cca644d2a27dd0959622"
  next-in-thread="2009/01/a8e2aeb057222710dd188876f1b96cc8"
  prev-thread="2009/01/9921cb683ab06368e880d42f5319d6ce"
  next-thread="2009/01/44166bc88a034e1581bc385cbd06574b"
  root="../../"
  period="month"
  listname="caml-list"
  title="Archives of the Caml mailing list">

<thread subject="Building with OCamlMkLib">
<msg 
  url="2009/01/fa6c4452c1d8f79eeb50fa71a9e2e430"
  from="John Whitington &lt;john@c...&gt;"
  author="John Whitington"
  date="2009-01-20T17:03:59"
  subject="Building with OCamlMkLib">
<msg 
  url="2009/01/8feeca3b384c260c274f1fff24d8962f"
  from="Alain Frisch &lt;alain@f...&gt;"
  author="Alain Frisch"
  date="2009-01-20T17:22:37"
  subject="Re: [Caml-list] Building with OCamlMkLib">
</msg>
<msg 
  url="2009/01/7b91d248f034cca644d2a27dd0959622"
  from="Matthieu Dubuget &lt;matthieu.dubuget@g...&gt;"
  author="Matthieu Dubuget"
  date="2009-01-20T21:35:49"
  subject="Re: [Caml-list] Building with OCamlMkLib">
</msg>
<msg 
  url="2009/01/2a7886bfc158bad05addcad2991a2059"
  from="Stefano Zacchiroli &lt;zack@u...&gt;"
  author="Stefano Zacchiroli"
  date="2009-01-21T14:43:29"
  subject="Re: [Caml-list] Building with OCamlMkLib">
</msg>
<msg 
  url="2009/01/a8e2aeb057222710dd188876f1b96cc8"
  from="John Whitington &lt;john@c...&gt;"
  author="John Whitington"
  date="2009-01-22T15:21:42"
  subject="Re: Building with OCamlMkLib">
</msg>
</msg>
</thread>

<contents>
On Tue, Jan 20, 2009 at 05:03:55PM +0000, John Whitington wrote:
&gt; I'm building a Plain C interface to our PDF libraries, but am
&gt; stuck. The idea is to build a library with Ocamlmklib containing the
&gt; 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 &lt;INCLUDE PATHS&gt; &lt;LIB PATHS&gt; -lcudf -lm -ldl -lunix -lncurses &lt;OTHER -l FOR EXTERNAL LIBS&gt;

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.

Cheers.

[1] http://gforge.info.ucl.ac.be/plugins/scmsvn/viewcvs.php/trunk/updb/libcudf/c-lib/?root=mancoosi

-- 
Stefano Zacchiroli -o- PhD in Computer Science \ PostDoc @ Univ. Paris 7
zack@{upsilon.cc,pps.jussieu.fr,debian.org} -&lt;&gt;- http://upsilon.cc/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

</contents>

</message>

