[
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: | -- (:) |
| From: | David LONY <david.lony@p...> |
| Subject: | Interface C and Caml |
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