Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calling Haskell from Java, dynamic linking error Relocation

I'm having troubles with compiling a standalone library for use by Java (with C++ inbetween). There is a program in Haskell exporting one function that processes some text and returns it. The program in Haskell needs some external data (binary file). I'm 'compiling it in' with the help of file-embed package. When I started the compilation with:

$ ghc -fPIC -dynamic -c -O --make MyModule.hs

It throws the error:

MyModule.hs:239:15:
Dynamic linking required, but this is a non-standard build (eg. prof).
You need to build the program twice: once the normal way, and then
in the desired way using -osuf to set the object file suffix.

This is the place where I use file-embed.

So I tried the proposed approach (compiling twice, changing suffixes):

$ ghc -fPIC  -c -O --make MyModule.hs
$ ghc -osuf d.o -fPIC -dynamic -c -O --make MyModule.hs
$ javac -cp javacpp.jar MyModule.java
$java -jar javacpp.jar -Dcompiler.path=ghc -Dcompiler.output.prefix="-optc-O3 -Wall MyModule.d.o -dynamic -fPIC -shared -lstdc++ -lHSrts-ghc7.6.3 -o " -Dcompiler.linkpath.prefix2="-optl -Wl,-rpath," MyModule

And now I'm getting an error that I don't understand:

/usr/bin/ld: MyModule.d.o: relocation R_X86_64_PC32 against undefined symbol `{Directory_with_code}zi{Some_module}_{Some_module}_con_info' can not be used when making a shared object; recompile with -fPIC

Can anyone explain it to me and give some tips on how to solve it?

like image 775
niczka Avatar asked May 22 '14 07:05

niczka


1 Answers

Just a guess, but maybe you need to different version of HSrts-ghc-7.6.3 since this is a "non-standard" build.

like image 109
Boyd Stephen Smith Jr. Avatar answered Nov 17 '22 17:11

Boyd Stephen Smith Jr.