Browse thread
Building with OCamlMkLib
- John Whitington
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2009-01-20 (17:03) |
From: | John Whitington <john@c...> |
Subject: | Building with OCamlMkLib |
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/