From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p8EFxbX7026636 for ; Wed, 14 Sep 2011 17:59:38 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgYCACnPcE7RVaE0imdsb2JhbABBp18IFAEBAQoJDQcSBiKBUwEBAQECARICLAEBNwEECws0EjQBBQEcBjWHVQKYRwqOFwGOcAWGDmCgPT2DcA X-IronPort-AV: E=Sophos;i="4.68,381,1312149600"; d="scan'208";a="109073311" Received: from mail-fx0-f52.google.com ([209.85.161.52]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 14 Sep 2011 17:59:28 +0200 Received: by fxe23 with SMTP id 23so2919120fxe.39 for ; Wed, 14 Sep 2011 08:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=PP+8YmoAm9XCWKrMbmMZYi4d3xBQqcCIH0iqKvJwfis=; b=q07N/LyvAtUtb07AR3SC+RKV1WstVPWVEAMKyP2wnOSynDILiEj6E+USO9Q8Cq6ia/ 7BKoRXPuaJkBkNcRMstyDll+Ta8kl7SsM9PBlou9z1BC1fA++tjv1GUh3LiDcK97SMqP +6kxO6nec1EIxXEgmYHLU7LNH8YWoHfi4k5/A= Received: by 10.223.27.8 with SMTP id g8mr17163fac.52.1316015967362; Wed, 14 Sep 2011 08:59:27 -0700 (PDT) Received: from coruscant.kosmos.all (ip-95-223-170-32.unitymediagroup.de. [95.223.170.32]) by mx.google.com with ESMTPS id b10sm3794330fam.1.2011.09.14.08.59.25 (version=SSLv3 cipher=OTHER); Wed, 14 Sep 2011 08:59:26 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1244.3) Content-Type: text/plain; charset=iso-8859-1 From: Benedikt Meurer In-Reply-To: <4E70CEAE.8030807@lri.fr> Date: Wed, 14 Sep 2011 17:59:24 +0200 Cc: OCaml List Message-Id: <33CE5892-E862-47D0-9ECA-3C1D7BD9EA2A@googlemail.com> References: <4E70C18F.3040304@lri.fr> <83695D27-A767-438A-B909-6864D1A655FE@googlemail.com> <4E70CEAE.8030807@lri.fr> To: Romain Bardou X-Mailer: Apple Mail (2.1244.3) Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by walapai.inria.fr id p8EFxbX7026636 Subject: Re: [Caml-list] Link a .so/.dll dynamically On Sep 14, 2011, at 17:56 , Romain Bardou wrote: > Le 14/09/2011 17:09, Benedikt Meurer a écrit : >> >>> 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 > > 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. $ ocamlmklib -ldopt -shared wrapper.o mylib.cmx -o mylib > Romain Bardou Benedikt