nic*_*zka 21 java haskell dynamic dynamic-linking
我在编译一个供Java使用的独立库时遇到了麻烦(C++ inbetween).Haskell中有一个程序导出一个处理某些文本并返回它的函数.Haskell中的程序需要一些外部数据(二进制文件).我正在'借助file-embed包编译它' .当我开始编译时:
$ ghc -fPIC -dynamic -c -O --make MyModule.hs
Run Code Online (Sandbox Code Playgroud)
它抛出错误:
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.
Run Code Online (Sandbox Code Playgroud)
这是我使用file-embed的地方.
所以我尝试了所提出的方法(编译两次,更改后缀):
$ 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
Run Code Online (Sandbox Code Playgroud)
现在我收到一个我不明白的错误:
/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
Run Code Online (Sandbox Code Playgroud)
任何人都可以向我解释并提供一些如何解决它的提示吗?