From: John Whitington <john@coherentgraphics.co.uk>
To: caml-list@yquem.inria.fr
Subject: Building with OCamlMkLib
Date: Tue, 20 Jan 2009 17:03:55 +0000 [thread overview]
Message-ID: <B6E31133-DB91-4453-BC16-70A3840E8E7A@coherentgraphics.co.uk> (raw)
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/
next reply other threads:[~2009-01-20 17:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-20 17:03 John Whitington [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=B6E31133-DB91-4453-BC16-70A3840E8E7A@coherentgraphics.co.uk \
--to=john@coherentgraphics.co.uk \
--cc=caml-list@yquem.inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox