caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Building with OCamlMkLib
@ 2009-01-20 17:03 John Whitington
  2009-01-20 17:22 ` [Caml-list] " Alain Frisch
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: John Whitington @ 2009-01-20 17:03 UTC (permalink / raw)
  To: caml-list

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 -> int

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

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

/* cpdflibwrapper.c */
#include <stdio.h>
#include <caml/memory.h>
#include <caml/callback.h>

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 <stdio.h>
#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/




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-01-22 15:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-20 17:03 Building with OCamlMkLib John Whitington
2009-01-20 17:22 ` [Caml-list] " Alain Frisch
2009-01-20 21:35 ` Matthieu Dubuget
2009-01-21 14:43 ` Stefano Zacchiroli
2009-01-22 15:21 ` John Whitington

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).