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

--
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to