簡體   English   中英

OSError:/usr/lib/ghc/ghc-prim-0.5.2.0/libHSghc-prim-0.5.2.0-ghc8.4.4.so:未定義符號:stg_gc_unpt_r1

[英]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

我正在嘗試從 github 運行此示例:https://github.com/nh2/haskell-from-python/blob/master/Makefile我想了解如何從另一種語言運行一種語言。 我不確定 FFI 是否在這里發揮了某種作用,我只是不知道如何判斷。

我在 WSL - debian 上運行代碼。 我也嘗試在 windows 上運行它,但我遇到了同樣的問題。 我的錯誤是在運行'make'然后'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 的經驗,因此我們將不勝感激任何幫助和耐心。

我嘗試過的事情:

  • 使用 -no-hs-main 選項運行
  • 閱讀 ghc 文檔
  • 發布 github 問題
  • 將 GHC_RUNTIME_LINKER_FLAG 中的 ghc 版本更改為 8.4.4,我當前的版本

我在這里假設您的 GHC 是通過 Debian ghc package 安裝的,因此它位於/usr/bin/ghc中,並且/usr/lib/ghc中的 GHC 庫是正確的相應版本。

如果是這樣,問題似乎是您的libffi-example.so未與定義丟失符號的/usr/lib/ghc/rts/libHSrts-ghc8.4.4.so鏈接。

確保文件/usr/lib/ghc/rts/libHSrts-ghc8.4.4.so存在,並嘗試以下設置:

GHC_RUNTIME_LINKER_FLAG=-L/usr/lib/ghc/rts -lHSrts-ghc8.4.4

然后執行make clean-allmake example 如果您已經鏈接了損壞的libffi-example.somake clean-all將很重要,因此不要跳過該步驟。 樣品 output:

$ make clean-all
rm -f *.hi *.o *_stub.[ch] *.so
$ 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.4.4
python program.py
Haskell fib(0): 0
Haskell fib(1): 1
[etc.]

如果這不起作用,請將ldd libffi-example.so的 output 添加到您的問題中,我們將看看我們能做什么。 在使用 GHC 8.10.4 構建和運行此示例時,我的看起來像這樣。 請注意libHSghc-prim-0.6.1-ghc8.10.4.so的行,它需要符號stg_gc_unpt_r1libHSrts-ghc8.10.4 ,它提供了它。

$ ldd libffi-example.so
    linux-vdso.so.1 (0x00007ffeee354000)
    libHSrts-ghc8.10.4.so => /scratch/buhr/stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/rts/libHSrts-ghc8.10.4.so (0x00007f9ef02dc000)
    libHSbase-4.14.1.0-ghc8.10.4.so => /scratch/buhr/stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/base-4.14.1.0/libHSbase-4.14.1.0-ghc8.10.4.so (0x00007f9eef919000)
    libHSinteger-gmp-1.0.3.0-ghc8.10.4.so => /scratch/buhr/stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/integer-gmp-1.0.3.0/libHSinteger-gmp-1.0.3.0-ghc8.10.4.so (0x00007f9eef8d9000)
    libHSghc-prim-0.6.1-ghc8.10.4.so => /scratch/buhr/stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/ghc-prim-0.6.1/libHSghc-prim-0.6.1-ghc8.10.4.so (0x00007f9eef43f000)
    libgmp.so.10 => /usr/lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f9eef38c000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f9eef19a000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f9eef04b000)
    libffi.so.7 => /scratch/buhr/stack/programs/x86_64-linux/ghc-tinfo6-8.10.4/lib/ghc-8.10.4/rts/libffi.so.7 (0x00007f9eeee3d000)
    librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f9eeee32000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f9eeee2c000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f9eeee07000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f9ef035c000)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM