我正试图从github运行此示例:https://github.com/nh2/haskell-from-python/blob/master/Makefile我想了解一下如何从另一种语言运行一种语言。我不确定外国金融机构是否以某种方式在这里发挥了作用,我只是不知道该怎么说。
我正在WSL-debian上运行代码。我也试过在windows上运行它,但我遇到了同样的问题。我的错误是在运行"make"one_answers"python program.py"之后我得到:
Traceback (most recent call last):
File "program.py", line 5, in <module>
lib = cdll.LoadLibrary("./libffi-example.so")
File "/usr/lib/python2.7/ctypes/__init__.py", line 444, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/lib/ghc/ghc-prim-0.5.2.0/libHSghc-prim-0.5.2.0-ghc8.4.4.so: undefined symbol: stg_gc_unpt_r1
我不知道stg_gc_unput_r1是什么,它在任何代码中都不是变量。我还查阅了GHC的一些文件,但没有找到任何内容。我关于存储库的问题没有得到任何关注,尽管我发布它才一天,但代码已经有好几年的历史了。
我没有使用Haskell和ghc的经验,也很少使用Python,所以如果有任何帮助和耐心,我将不胜感激。
在检查文件/usr/lib/ghc/rts/libHSrts-ghc8.4.4.so
确实存在之后,以下是运行ldd libffi-example.so
:的输出
linux-vdso.so.1 (0x00007ffd5f5ee000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fcc439c7000)
libHSbase-4.11.1.0-ghc8.4.4.so => /usr/lib/ghc/base-4.11.1.0/libHSbase-4.11.1.0-ghc8.4.4.so (0x00007fcc4304c000)
libHSinteger-gmp-1.0.2.0-ghc8.4.4.so => /usr/lib/ghc/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0-ghc8.4.4.so (0x00007fcc43009000)
libHSghc-prim-0.5.2.0-ghc8.4.4.so => /usr/lib/ghc/ghc-prim-0.5.2.0/libHSghc-prim-0.5.2.0-ghc8.4.4.so (0x00007fcc42b7b000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007fcc42af8000)
libatomic.so.1 => /usr/lib/x86_64-linux-gnu/libatomic.so.1 (0x00007fcc42aec000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fcc4292b000)
/lib64/ld-linux-x86-64.so.2 (0x00007fcc43b58000)
libffi.so.6 => /usr/lib/x86_64-linux-gnu/libffi.so.6 (0x00007fcc42921000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fcc42900000)
我尝试过的东西:
- 使用-no-hs主选项运行
- 阅读ghc文档
- 发布github问题
- 将ghc_RUNTIME_LINKER_FLAG中的ghc版本更改为8.4.4,即我的当前版本
我已经尝试在WSL安装下使用新的Debian来复制您的问题。我在管理Debian"牛眼;在Windows 10下的WSL 1下。Debian版本一定比您的版本更新一点,因为GHC包是版本8.8.4,而不是8.4.4,但这似乎是唯一的区别。
使用该Git存储库的干净副本(提交9c3b6315
(,只更改了Makefile
(与下面完全相同,除了通常的"tab"缩进(:
GHC=ghc
GHC_RUNTIME_LINKER_FLAG=-L/usr/lib/ghc/rts -lHSrts-ghc8.8.4
libffi-example.so: Example.o wrapper.o
$(GHC) -o $@ -shared -dynamic -fPIC $^ $(GHC_RUNTIME_LINKER_FLAG)
Example_stub.h Example.o: Example.hs
$(GHC) -c -dynamic -fPIC Example.hs
wrapper.o: wrapper.c Example_stub.h
$(GHC) -c -dynamic -fPIC wrapper.c
clean:
rm -f *.hi *.o *_stub.[ch]
clean-all:
rm -f *.hi *.o *_stub.[ch] *.so
# Runs the example Python program
example: libffi-example.so
python program.py
我可以运行以下命令:
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ make clean-all
rm -f *.hi *.o *_stub.[ch] *.so
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ make example
ghc -c -dynamic -fPIC Example.hs
ghc -c -dynamic -fPIC wrapper.c
ghc -o libffi-example.so -shared -dynamic -fPIC Example.o wrapper.o -L/usr/lib/ghc/rts -lHSrts-ghc8.8.4
python program.py
Haskell fib(0): 0
Haskell fib(1): 1
Haskell fib(2): 1
Haskell fib(3): 2
Haskell fib(4): 3
Haskell fib(5): 5
Haskell fib(6): 8
Haskell fib(7): 13
Haskell fib(8): 21
Haskell fib(9): 34
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ ldd libffi-example.so
linux-vdso.so.1 (0x00007ffff6925000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7c7b810000)
libHSrts-ghc8.8.4.so => /usr/lib/ghc/rts/libHSrts-ghc8.8.4.so (0x00007f7c7b7a0000)
libHSbase-4.13.0.0-ghc8.8.4.so => /usr/lib/ghc/base-4.13.0.0/libHSbase-4.13.0.0-ghc8.8.4.so (0x00007f7c7ae00000)
libHSinteger-gmp-1.0.2.0-ghc8.8.4.so => /usr/lib/ghc/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0-ghc8.8.4.so (0x00007f7c7adc0000)
libHSghc-prim-0.5.3-ghc8.8.4.so => /usr/lib/ghc/ghc-prim-0.5.3/libHSghc-prim-0.5.3-ghc8.8.4.so (0x00007f7c7a920000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f7c7a880000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7c7a6b0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7c7b973000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7c7a6a0000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7c7a690000)
libffi.so.7 => /usr/lib/x86_64-linux-gnu/libffi.so.7 (0x00007f7c7a680000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7c7a65e000)
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$
如果我故意破坏Makefile
,比如说,通过注释掉GHC_RUNTIME_LINKER_FLAG
链接或拼错它,使其实际上不包含在libffi-example.so
链接命令中,那么我可以完全复制您的问题。请注意以下转录本中Makefile
第二行的_MISTAKE
,它会阻止RTS库实际链接:
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ head Makefile
GHC=ghc
GHC_RUNTIME_LINKER_FLAG_MISTAKE=-L/usr/lib/ghc/rts -lHSrts-ghc8.8.4
libffi-example.so: Example.o wrapper.o
$(GHC) -o $@ -shared -dynamic -fPIC $^ $(GHC_RUNTIME_LINKER_FLAG)
Example_stub.h Example.o: Example.hs
$(GHC) -c -dynamic -fPIC Example.hs
wrapper.o: wrapper.c Example_stub.h
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ make clean-all
rm -f *.hi *.o *_stub.[ch] *.so
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ make example
ghc -c -dynamic -fPIC Example.hs
ghc -c -dynamic -fPIC wrapper.c
ghc -o libffi-example.so -shared -dynamic -fPIC Example.o wrapper.o
python program.py
Traceback (most recent call last):
File "program.py", line 4, in <module>
lib = cdll.LoadLibrary("./libffi-example.so")
File "/usr/lib/python2.7/ctypes/__init__.py", line 444, in LoadLibrary
return self._dlltype(name)
File "/usr/lib/python2.7/ctypes/__init__.py", line 366, in __init__
self._handle = _dlopen(self._name, mode)
OSError: /usr/lib/ghc/ghc-prim-0.5.3/libHSghc-prim-0.5.3-ghc8.8.4.so: undefined symbol: stg_gc_unpt_r1
make: *** [Makefile:22: example] Error 1
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$ ldd libffi-example.so
linux-vdso.so.1 (0x00007fffea75d000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f83175e0000)
libHSbase-4.13.0.0-ghc8.8.4.so => /usr/lib/ghc/base-4.13.0.0/libHSbase-4.13.0.0-ghc8.8.4.so (0x00007f8316c40000)
libHSinteger-gmp-1.0.2.0-ghc8.8.4.so => /usr/lib/ghc/integer-gmp-1.0.2.0/libHSinteger-gmp-1.0.2.0-ghc8.8.4.so (0x00007f8316c00000)
libHSghc-prim-0.5.3-ghc8.8.4.so => /usr/lib/ghc/ghc-prim-0.5.3/libHSghc-prim-0.5.3-ghc8.8.4.so (0x00007f8316760000)
libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f83166d0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f83164f0000)
/lib64/ld-linux-x86-64.so.2 (0x00007f8317741000)
libffi.so.7 => /usr/lib/x86_64-linux-gnu/libffi.so.7 (0x00007f83164e0000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f83164be000)
buhr@DESKTOP-585NUKU:~/src/haskell-from-python$
在我看来,在实验过程中,你不知何故破坏了你的Makefile
,所以它实际上并没有与/usr/lib/ghc/libHSrts-ghc8.4.4.so
联系起来。