22

我正在尝试在 Fedora 中安装带有 -fPIC 支持的 GHC。我已经抓住了一个源代码压缩包,因为它似乎没有二进制文件有这个。

在 Build.mk 中,我将快速构建类型更改为

ifeq "$(BuildFlavour)" "quick"

SRC_HC_OPTS        = -H64m -O0 -fasm -fPIC
GhcStage1HcOpts    = -O -fasm -fPIC
GhcStage2HcOpts    = -O0 -fasm -fPIC
GhcLibHcOpts       = -O -fasm -fPIC
SplitObjs          = NO
HADDOCK_DOCS       = NO
BUILD_DOCBOOK_HTML = NO
BUILD_DOCBOOK_PS   = NO
BUILD_DOCBOOK_PDF  = NO

endif

不幸的是,在编译时我仍然得到 ld 错误

ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math
Linking a.out ...
/usr/bin/ld: /tmp/Hs2lib924498/Hs2lib.o: relocation R_X86_64_32 against `ghczmprim_GHCziUnit_Z0T_closure' can not be used when making a shared object; recompile with -fPIC
/tmp/Hs2lib924498/Hs2lib.o: could not read symbols: Bad value

所以似乎 GHC-prim 仍然没有使用 -FPIC 编译我还告诉 cabal 使用 -fPIC 构建任何包并共享。

有人有想法么?

编辑:感谢 dcouts 我已经能够取得一些进展。但是现在我正处于我认为 libffi 没有使用 -fPIC 编译的地步。我已经为它编辑了makefile(.in),但到目前为止,还没有运气。

新命令是:

 ghc -fPIC -shared dllmain.o Hs2lib.o /usr/local/lib/ghc-7.0.3/libHSrts.a -o Hs2lib.so

其中 dllmain.c 和 Hs2lib.hs 均已使用 -fPIC 编译。我得到的错误是:

/usr/bin/ld: /usr/local/lib/ghc-7.0.3/libHSffi.a(closures.o): relocation R_X86_64_32 
against `.rodata' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib/ghc-7.0.3/libHSffi.a: could not read symbols: Bad value

collect2: ld 返回 1 个退出状态

4

2 回答 2

1

After you see this error, do the following:

cd /tmp/Hs2lib924498/
ghc -fglasgow-exts --make -shared -oHs2lib.a /tmp/Hs2lib924498/Hs2lib.hs dllmain.o -static -fno-warn-deprecated-flags -fPIC -O2 -package ghc -package Hs2lib -i/home/phyx/Documents/Haskell/Hs2lib -optl-Wl,-s -funfolding-use-threshold=16 -optc-O3 -optc-ffast-math

Note I added -fPIC to the failed ghc command.

Once the command succeeds, continue the compilation from within the tmp directory without cleaning already compiled files. It should skip them and continue where it ended.

于 2011-12-10T02:05:04.620 回答
0

Haskell Stack 页面上有关于此主题的常见问题解答条目。

它基本上说问题与环境有关,有时是不确定的。

在某些情况下,该问题可能与使用强化标志有关,特别是与生成与位置无关的可执行文件 (PIE) 有关的那些。

还有一个针对 Arch Linux 的建议:

在 Arch Linux 上,从 AUR 安装 ncurses5-compat-libs 包可以解决这个问题。

于 2017-11-30T07:14:52.797 回答