从 Java 调用 Haskell,动态链接错误重定位

2022-09-02 04:52:39

我在编译一个由Java使用的独立库时遇到了麻烦(中间有C++)。Haskell中有一个程序导出一个函数,该函数处理一些文本并返回它。Haskell中的程序需要一些外部数据(二进制文件)。我在文件嵌入包的帮助下“编译它”。当我开始编译时:

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

它会抛出错误:

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.

这是我使用文件嵌入的地方。

所以我尝试了建议的方法(编译两次,更改后缀):

$ 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

现在我得到了一个我不明白的错误:

/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

任何人都可以向我解释一下,并给出一些如何解决它的提示?


答案 1

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


答案 2

推荐