Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Interface C and Caml
@ 2008-01-03 14:54 David LONY
  2008-01-03 20:03 ` [Caml-list] " Alain Frisch
  0 siblings, 1 reply; 3+ messages in thread
From: David LONY @ 2008-01-03 14:54 UTC (permalink / raw)
  To: caml-list

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


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

end of thread, other threads:[~2008-01-04  9:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-01-03 14:54 Interface C and Caml David LONY
2008-01-03 20:03 ` [Caml-list] " Alain Frisch
2008-01-04  9:24   ` David LONY

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox