caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Benedikt Meurer <benedikt.meurer@googlemail.com>
To: Romain Bardou <bardou@lri.fr>
Cc: OCaml List <caml-list@yquem.inria.fr>
Subject: Re: [Caml-list] Link a .so/.dll dynamically
Date: Wed, 14 Sep 2011 17:59:24 +0200	[thread overview]
Message-ID: <33CE5892-E862-47D0-9ECA-3C1D7BD9EA2A@googlemail.com> (raw)
In-Reply-To: <4E70CEAE.8030807@lri.fr>


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



  reply	other threads:[~2011-09-14 15:59 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-14 15:00 Romain Bardou
2011-09-14 15:35 ` Benedikt Meurer
     [not found] ` <83695D27-A767-438A-B909-6864D1A655FE@googlemail.com>
2011-09-14 15:56   ` Romain Bardou
2011-09-14 15:59     ` Benedikt Meurer [this message]
2011-09-14 16:03       ` Romain Bardou
2011-09-14 16:07         ` Jérémie Dimino
2011-09-14 16:07     ` Stéphane Glondu
2011-09-14 16:12       ` Romain Bardou
2011-09-14 16:34         ` Stéphane Glondu
2011-09-14 16:42           ` Romain Bardou
2011-09-14 16:56             ` Stéphane Glondu
2011-09-15  8:49               ` Romain Bardou
2011-09-15  9:20                 ` Stéphane Glondu
2011-09-15  9:23                   ` Romain Bardou
2011-09-15  9:05               ` Romain Bardou
2011-09-14 16:15 ` Jérémie Dimino

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=33CE5892-E862-47D0-9ECA-3C1D7BD9EA2A@googlemail.com \
    --to=benedikt.meurer@googlemail.com \
    --cc=bardou@lri.fr \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).