<?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/8feeca3b384c260c274f1fff24d8962f"
  from="Alain Frisch &lt;alain@f...&gt;"
  author="Alain Frisch"
  date="2009-01-20T17:22:37"
  subject="Re: [Caml-list] Building with OCamlMkLib"
  prev="2009/01/bec8514bf8ec8e4b7403d82c8845ffa0"
  next="2009/01/7bf500ce00c1bd15b48f1a563855c516"
  prev-in-thread="2009/01/fa6c4452c1d8f79eeb50fa71a9e2e430"
  next-in-thread="2009/01/7b91d248f034cca644d2a27dd0959622"
  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>
John Whitington wrote:
&gt; Hi Folks,
&gt; 
&gt; I'm building a Plain C interface to our PDF libraries, but am stuck. The 
&gt; idea is to build a library with Ocamlmklib containing the C wrapper 
&gt; around the ocaml code.
&gt; 
&gt; I've used some test files (included below) in place of the real ones.
&gt; 
&gt; I can successfully build the library (I'm using OS x / intel):
&gt; 
&gt; ocamlc -c -cc "cc" -ccopt " -DNATIVE_CODE -o cpdflibwrapper.o" 
&gt; cpdflibwrapper.c
&gt; ocamlc cpdflibc.mli
&gt; ocamlc cpdflibc.ml
&gt; ocamlmklib -o camlpdfc cpdflibc.ml cpdflibwrapper.a
&gt; 
&gt; (builds dllcamlpdfc.so, camlpdfc.a, camlpdfc.cma, camlpdfc.cmxa)
&gt; 
&gt; But trying to link a C program which uses the new library fails. Do I 
&gt; need to include something else, or have I got the ocamlmklib stage wrong?

You need to include an OCaml "main program" into your library. The 
easiest way to build a library that include the OCaml runtime, some 
OCaml code and custom C code is the -output-obj option:

ocamlc -output-obj -o camlpdfc.so cpdlibc.cmo cpdflibwrapper.o

Note that cpdflibrwrapper should define a function that calls 
caml_startup in order to start the OCaml runtime and run the OCaml code.

If you want to build a static library, you can use "-output-obj -o 
camlpdf.o" and then create the library yourself.

-- Alain

</contents>

</message>

