From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8EG7a9r027223 for ; Wed, 14 Sep 2011 18:07:37 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AuoDANDQcE6K54gDgWdsb2JhbABBp2cUAQEWJiaBUwEBBTIBRQEQCxgJFg8JAwIBAgFFBg0BBwEBvVCGbgSTP4UbjAw X-IronPort-AV: E=Sophos;i="4.68,381,1312149600"; d="scan'208";a="119832305" Received: from rouge.crans.org ([138.231.136.3]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 14 Sep 2011 18:07:37 +0200 Received: from localhost (localhost.crans.org [127.0.0.1]) by rouge.crans.org (Postfix) with ESMTP id 11AEC8619; Wed, 14 Sep 2011 18:07:35 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at crans.org Received: from rouge.crans.org ([10.231.136.3]) by localhost (rouge.crans.org [10.231.136.3]) (amavisd-new, port 10024) with LMTP id UwRSHGWvfbaB; Wed, 14 Sep 2011 18:07:34 +0200 (CEST) Received: from [152.81.12.138] (fleur.loria.fr [152.81.12.138]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by rouge.crans.org (Postfix) with ESMTPSA id D6E678618; Wed, 14 Sep 2011 18:07:33 +0200 (CEST) Message-ID: <4E70D140.8030507@glondu.net> Date: Wed, 14 Sep 2011 18:07:28 +0200 From: =?ISO-8859-1?Q?St=E9phane_Glondu?= User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.21) Gecko/20110831 Thunderbird/3.1.13 MIME-Version: 1.0 To: Romain Bardou CC: Benedikt Meurer , OCaml List References: <4E70C18F.3040304@lri.fr> <83695D27-A767-438A-B909-6864D1A655FE@googlemail.com> <4E70CEAE.8030807@lri.fr> In-Reply-To: <4E70CEAE.8030807@lri.fr> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit Subject: Re: [Caml-list] Link a .so/.dll dynamically On 09/14/2011 05:56 PM, Romain Bardou wrote: > [...] > ocamlopt -c -ccopt -fPIC wrapper.c > ocamlopt -c mylib.ml > ocamlmklib wrapper.o mylib.cmx -o mylib > ocamlopt -c main.ml > ocamlopt dynlink.cmxa main.cmx -o main > CAML_LD_LIBRARY_PATH=. ./main mylib.cmxa > > But when Dynlink.load is called, it fails with the following error: > > error loading shared library: /home/.../mylib.cmxa: invalid ELF header > > I'm thinking this is because the .cmxa has not been compiled with the > -shared option, but I don't know how to tell ocamlmklib to compile with > the -shared option. You can turn the .cmxa generated by ocamlmklib into a .cmxs by calling (for example): ocamlopt -shared -I . -linkall -o mylib.cmxs mylib.cmxa The .cmxs should then be loadable by Dynlink.load. Cheers, -- Stéphane