From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr 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 84427BBAF for ; Tue, 24 Aug 2010 19:50:38 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: Am4GAOuic0xQDPIuYGdsb2JhbACgQQsXCwgGFAMfoCWae4U3BIQ1 X-IronPort-AV: E=Sophos;i="4.56,263,1280700000"; d="scan'208";a="68167630" Received: from smtp21.orange.fr ([80.12.242.46]) by mail4-smtp-sop.national.inria.fr with ESMTP; 24 Aug 2010 19:50:38 +0200 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2103.orange.fr (SMTP Server) with ESMTP id 1172B20002C1 for ; Tue, 24 Aug 2010 19:50:38 +0200 (CEST) Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2103.orange.fr (SMTP Server) with ESMTP id 03213200159A for ; Tue, 24 Aug 2010 19:50:38 +0200 (CEST) Received: from [172.24.131.5] (out1-1601fw.corp.tfbnw.net [66.220.144.27]) by mwinf2103.orange.fr (SMTP Server) with ESMTP id 9033320002C1 for ; Tue, 24 Aug 2010 19:50:37 +0200 (CEST) X-ME-UUID: 20100824175037590.9033320002C1@mwinf2103.orange.fr X-ME-User-Auth: padator@wanadoo.fr From: Yoann Padioleau Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable Subject: how to call an OCaml library from C/C++ ? Date: Tue, 24 Aug 2010 10:50:36 -0700 Message-Id: <1FEF5EC1-5F99-4400-A787-63A8352DDF85@wanadoo.fr> To: caml users Mime-Version: 1.0 (Apple Message framework v1078) X-Mailer: Apple Mail (2.1078) X-Spam: no; 0.00; ocaml:01 ocaml:01 char:01 char:01 ideally:01 caml:02 caml:02 library:03 library:03 cleanup:04 cleanup:04 startup:05 startup:05 extension:06 extension:06 Hi, Is there a way to call OCaml library from a C/C++ program without the = C++ program knowing it's OCaml code ? I mean I can not touch the main of the C++ = program so it has to be completely transparent and it would be good if each call = to the ocaml library once finished free all the memory it was using. Can we call caml_startup() multiple times ? is there a caml_cleanup ? Ideally I would like from C/C++ to have: my_extension.c: char* sanitize_stuff(char *s) { caml_startup(); char * res =3D ; caml_cleanup(); return res; } and then link my c++ program with my_extension.o and some .a containing = ocaml code.