From: David LONY <david.lony@pragmadev.com>
To: caml-list@yquem.inria.fr
Subject: Interface C and Caml
Date: Thu, 03 Jan 2008 15:54:51 +0100 [thread overview]
Message-ID: <477CF73B.9050406@pragmadev.com> (raw)
Hi all,
I'm trying to interface Ocaml with C code. But unfortunately I don't
know why it doesn't work well...
This is my caml code (truc.ml) :
let test_char a = a+1
let _ = Callback.register "caml_test_char" test_char;;
and this is my C code (test.c) :
#include <stdio.h>
#include <caml/mlvalues.h>
#include <caml/callback.h>
int test_char(int n)
{
static value * test_char_closure = NULL;
if (test_char_closure == NULL)
{
test_char_closure = caml_named_value("caml_test_char");
}
return Int_val(caml_callback(*test_char_closure, Val_int(n)));
}
int main(int argc, char ** argv)
{
int result;
caml_startup(argv);
result = test_char(10);
printf("%d\n", result);
return 0;
}
I obtain the final executable by typing this command :
ocamlopt -cc "gcc" -o test truc.ml test.c
But if I try to do the same thing by typing :
ocamlopt -output-obj truc.ml -o truc.o
gcc -c test.c
gcc -o test test.o truc.o -L/usr/lib/ocaml/3.09.2 -lasmrun
I obtain :
truc.o: In function `caml_program':
(.text+0xd): undefined reference to `camlTruc__entry'
truc.o: In function `caml_globals':
(.data+0x1b4): undefined reference to `camlTruc'
truc.o: In function `caml_data_segments':
(.data+0x21c): undefined reference to `camlTruc__data_begin'
truc.o: In function `caml_data_segments':
(.data+0x220): undefined reference to `camlTruc__data_end'
truc.o: In function `caml_code_segments':
----BLABLA
/usr/lib/ocaml/3.09.2/libasmrun.a(floats.o): In function `caml_atan_float':
----BLABLA
/usr/lib/ocaml/3.09.2/libasmrun.a(floats.o): In function `caml_power_float':
(.text+0x380): undefined reference to `pow'
/usr/lib/ocaml/3.09.2/libasmrun.a(floats.o): In function `caml_sqrt_float':
(.text+0x3b1): undefined reference to `sqrt'
/usr/lib/ocaml/3.09.2/libasmrun.a(floats.o): In function `caml_log10_float':
(.text+0x492): undefined reference to `log10'
/usr/lib/ocaml/3.09.2/libasmrun.a(floats.o): In function `caml_log_float':
/usr/lib/ocaml/3.09.2/libasmrun.a(unix.o): In function `caml_dlclose':
----BLABLA
What is wrong ? Does anyone has the same problem ?
Regards
David LONY
next reply other threads:[~2008-01-03 19:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-03 14:54 David LONY [this message]
2008-01-03 20:03 ` [Caml-list] " Alain Frisch
2008-01-04 9:24 ` David LONY
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=477CF73B.9050406@pragmadev.com \
--to=david.lony@pragmadev.com \
--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