From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id A6B2BBBC4 for ; Tue, 31 Jan 2006 11:59:41 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0VAxfVP021066 for ; Tue, 31 Jan 2006 11:59:41 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id LAA19580 for ; Tue, 31 Jan 2006 11:59:38 +0100 (MET) Received: from mail.libertysurf.net (mx-out.libertysurf.net [213.36.80.91]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id k0VAxaTv021051 for ; Tue, 31 Jan 2006 11:59:38 +0100 Received: from dyn-83-156-172-170.ppp.tiscali.fr (83.156.172.170) by mail.libertysurf.net (7.1.026) id 43DACD5D000855FE for caml-list@inria.fr; Tue, 31 Jan 2006 11:59:36 +0100 From: Florent Monnier Organization: l'Association Linux-Nantes To: caml-list@inria.fr Subject: callbacks from C to Caml Date: Tue, 31 Jan 2006 12:09:12 +0100 User-Agent: KMail/1.8.2 MIME-Version: 1.0 Content-Disposition: inline Message-Id: <200601311209.13125.fmonnier@linux-nantes.fr.eu.org> X-Face: "`cRNH1ww*pA7BMG\%C8RcGZR33F%q#d~:5U8b[K-NbYLSW_wpx@wk**lzqX3\F'a|gyP"K/emS.&rsSu'a7OiJH&d?,Z6OxW_L}I"z%\><#5LL%uQXl"QY@~9|XyM7{`tAq?Gp@ul&F'# Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 43DF431D.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at concorde with ID 43DF4318.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; compilation:01 ocamlopt:01 -output-obj:01 cmxa:01 cmx:01 cmxa:01 myprog:01 usr:01 lib:01 ocaml:01 -lunix:01 ocaml:01 gcc:01 3.09.0:01 -lm:01 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Hi, I'm trying to compile the simple exemple given here: http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html#htoc235 with the compilation instructions given there: http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html#htoc238 which are: ocamlopt -output-obj -o camlcode.o unix.cmxa other .cmx and .cmxa files cc -o myprog C objects and libraries \ camlcode.o -L/usr/local/lib/ocaml -lunix -lasmrun I have copy-past the OCaml code in test.ml and the C code in main.c I use a standard GNU/Linux box [Mandriva 2006], with gcc 4.0.1 and OCaml 3.09.0 First I got errors like this: undefined reference to `sqrt' so I added -lm to gcc Then those kind of errors: undefined reference to `dlopen' adding -ldl seems to be the solution. Then new errors like this: error: caml/mlvalues.h: No such file or directory it seems that adding this fixes: -I'/usr/local/lib/ocaml' Then the compilation is made with this: % ocamlopt -c test.ml % ocamlopt -output-obj -o camlcode.o unix.cmxa test.cmx % gcc main.c -o myprog.opt camlcode.o \ -I'/usr/local/lib/ocaml' \ -L/usr/local/lib/ocaml \ -lunix -lasmrun -lm -ldl Now the compilation is made without any error messages, but: % ./myprog.opt Segmentation Error What is wrong? Where is the error? What should I change/correct? -- Thanks in advance ________________ % cat test.ml let f n = print_string "f is applied to "; print_int n; print_newline(); let _ = Callback.register "test function" f; % cat main.c #include #include #include #include void call_caml_f(int arg) { static value * closure_f = NULL; if (closure_f == NULL) { /* First time around, look up by name */ closure_f = caml_named_value("test function"); } caml_callback(*closure_f, Val_int(arg)); } int main(void) { call_caml_f(2); call_caml_f(5); return 0; }