From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 17C0EBC69 for ; Thu, 3 Jan 2008 20:43:21 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAFbIfEfB/BYdlmdsb2JhbACQDwEBAQEHAggiB5lrghg X-IronPort-AV: E=Sophos;i="4.24,240,1196636400"; d="scan'208";a="20883108" Received: from smtp20.orange.fr ([193.252.22.29]) by mail4-smtp-sop.national.inria.fr with ESMTP; 03 Jan 2008 20:43:20 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2016.orange.fr (SMTP Server) with ESMTP id 5EBD91C0513B for ; Thu, 3 Jan 2008 19:32:49 +0100 (CET) Received: from [192.168.1.5] (ASt-Lambert-152-1-62-107.w82-120.abo.wanadoo.fr [82.120.199.107]) by mwinf2016.orange.fr (SMTP Server) with ESMTP id CB7A81C04217 for ; Thu, 3 Jan 2008 15:49:48 +0100 (CET) X-ME-UUID: 20080103144948833.CB7A81C04217@mwinf2016.orange.fr Message-ID: <477CF73B.9050406@pragmadev.com> Date: Thu, 03 Jan 2008 15:54:51 +0100 From: David LONY Organization: PRAGMADEV User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: Interface C and Caml Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Spam: no; 0.00; ocaml:01 stdio:01 mlvalues:01 val:01 val:01 argc:01 argv:01 argv:01 printf:01 ocamlopt:01 gcc:01 ocamlopt:01 -output-obj:01 gcc:01 usr:01 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 #include #include 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