<?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/fa6c4452c1d8f79eeb50fa71a9e2e430"
  from="John Whitington &lt;john@c...&gt;"
  author="John Whitington"
  date="2009-01-20T17:03:59"
  subject="Building with OCamlMkLib"
  prev="2009/01/9921cb683ab06368e880d42f5319d6ce"
  next="2009/01/bec8514bf8ec8e4b7403d82c8845ffa0"
  next-in-thread="2009/01/8feeca3b384c260c274f1fff24d8962f"
  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>
Hi Folks,

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 used some test files (included below) in place of the real ones.

I can successfully build the library (I'm using OS x / intel):

ocamlc -c -cc "cc" -ccopt " -DNATIVE_CODE -o cpdflibwrapper.o"  
cpdflibwrapper.c
ocamlc cpdflibc.mli
ocamlc cpdflibc.ml
ocamlmklib -o camlpdfc cpdflibc.ml cpdflibwrapper.a

(builds dllcamlpdfc.so, camlpdfc.a, camlpdfc.cma, camlpdfc.cmxa)

But trying to link a C program which uses the new library fails. Do I  
need to include something else, or have I got the ocamlmklib stage  
wrong?

feast:trunk john$ gcc test.c -o test_executable -L. -L/usr/local/lib/ 
ocaml -lcamlpdfc -lasmrun
Undefined symbols:
   "_caml_code_area_end", referenced from:
       _caml_code_area_end$non_lazy_ptr in libasmrun.a(signals_asm.o)
       _caml_code_area_end$non_lazy_ptr in libasmrun.a(intern.o)
       _caml_code_area_end$non_lazy_ptr in libasmrun.a(extern.o)
   "_caml_program", referenced from:
       _caml_start_program in libasmrun.a(i386.o)
   "_caml_bucket_Out_of_memory", referenced from:
       _caml_bucket_Out_of_memory$non_lazy_ptr in libasmrun.a(fail.o)

(many more lines)

Here are the input files forming the mixed ocaml/c library:

(* cpdflibc.mli *)
val twice : int -&gt; int

(* cpdflibc.ml *)
let twice x = x * 2

/* cpdflibwrapper.h */
int twice (int);

/* cpdflibwrapper.c */
#include &lt;stdio.h&gt;
#include &lt;caml/memory.h&gt;
#include &lt;caml/callback.h&gt;

int twice_c (int i)
{
   CAMLlocal1 (result);
   result = caml_callback(*caml_named_value("twice"), Val_int(i));
   return(0);
}

And here's the C program which will be using the libary:

/* test.c */
#include &lt;stdio.h&gt;
#include "cpdflibwrapper.h"

int main ()
{
   printf("Twice two is %i\n", twice_c(2));
   return(0);
}

Here's a zip containing those files: http://www.coherentpdf.com/files.zip

Any ideas?

-- 
John Whitington
Coherent Graphics Ltd
http://www.coherentpdf.com/



</contents>

</message>

