From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr 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 p8EFvTXR026216 for ; Wed, 14 Sep 2011 17:57:29 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AowBAH/OcE4uaUwamWdsb2JhbABBp3sBAQEBAQgLCwcUJoFTAQEFMgEFQBELGAkWDwkDAgECAUUGAQwIAod1tV2GbgSYeYtt X-IronPort-AV: E=Sophos;i="4.68,381,1312149600"; d="scan'208";a="119830360" Received: from 4.mo1.mail-out.ovh.net (HELO mo1.mail-out.ovh.net) ([46.105.76.26]) by mail1-smtp-roc.national.inria.fr with ESMTP; 14 Sep 2011 17:57:23 +0200 Received: from mail174.ha.ovh.net (b6.ovh.net [213.186.33.56]) by mo1.mail-out.ovh.net (Postfix) with SMTP id 35109FFC9DC for ; Wed, 14 Sep 2011 17:58:06 +0200 (CEST) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 14 Sep 2011 17:57:23 +0200 Received: from unknown (HELO ?138.231.81.43?) (romain%bardou.fr@138.231.81.43) by ns0.ovh.net with SMTP; 14 Sep 2011 17:57:22 +0200 Message-ID: <4E70CEAE.8030807@lri.fr> Date: Wed, 14 Sep 2011 17:56:30 +0200 From: Romain Bardou User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.20) Gecko/20110820 Icedove/3.1.12 MIME-Version: 1.0 To: Benedikt Meurer , OCaml List X-Ovh-Mailout: 178.32.228.1 (mo1.mail-out.ovh.net) References: <4E70C18F.3040304@lri.fr> <83695D27-A767-438A-B909-6864D1A655FE@googlemail.com> In-Reply-To: <83695D27-A767-438A-B909-6864D1A655FE@googlemail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Ovh-Tracer-Id: 14907477716984720114 X-Ovh-Remote: 138.231.81.43 () X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -200 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeftddrfeduucetggdotefuucfrrhhofhhilhgvmecuqfggjfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmneculddquddttddm X-Validation-by: bardou@lri.fr Subject: Re: [Caml-list] Link a .so/.dll dynamically Le 14/09/2011 17:09, Benedikt Meurer a écrit : > > On Sep 14, 2011, at 17:00 , Romain Bardou wrote: > >> My first problem is: I tried something similar for native code (using ocamlopt instead of ocamlc, .cmx instead of .cmo and .cmxa instead of .cma) but ocamlmklib fails with the following error: >> /usr/bin/ld: wrapper.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC >> wrapper.o: could not read symbols: Bad value >> collect2: ld returned 1 exit status >> I have absolutely no idea what this means, I'm really confused here and Google does not help. > > The error messages already includes the answer, you need to pass -fPIC to the C compiler when compiling wrapper.c, i.e. > > $ gcc -c -fPIC -o wrapper.o wrapper.c > >> Romain Bardou > > HTH, > Benedikt Thanks for your quick answer. Actually I tried adding the -fPIC option like this: 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. Cheers, -- Romain Bardou