简体   繁体   中英

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?

只是一个猜测,但也许您需要不同版本的HSrts-ghc-7.6.3,因为这是一个“非标准”构建。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM