使用堆栈安装 zlib:使用 -fPIC 重新编译

Installing zlib using stack: recompile with -fPIC

当我运行

stack --resolver=lts-7.14 install zlib

我收到消息说应该使用 -fPIC 标志重新编译包:

Configuring zlib-0.6.1.2...
Building zlib-0.6.1.2...
Preprocessing library zlib-0.6.1.2...
/usr/bin/ld: .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0/build/Codec/Compression/Zlib/Stream_hsc_make.o: relocation R_X86_64_32 against `.rodata' can not be used when making a shared object; recompile with -fPIC

如何告诉堆栈使用 -fPIC 标志重新编译 zlib


我在 yaml 文件中添加了 ghc-options:

ghc-options:
  zlib: -fPIC

apply-ghc-options: locals
rebuild-ghc-options: true

此外,我在 cabal 文件中的 ghc-options 添加了 -fPIC 标志。

但是,我仍然得到相同的输出:

--  While building package zlib-0.6.1.2 using:
  /home/vladimir/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.0.0_ghc-8.0.1 --builddir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.0.0 build --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1
Logs have been written to: /home/vladimir/Desktop/ffmpeg-light/.stack-work/logs/zlib-0.6.1.2.log

其中 ghc-options 是 -ddump-hi-ddump-to-file,没有 -fPIC。我错过了什么吗?


GCC、堆栈和 OS 版本:

海湾合作委员会:海湾合作委员会(Ubuntu 6.2.0-5ubuntu12)6.2.0 20161005

堆栈:版本 1.3.0,Git 修订版 99b910d3c8e183aa376cb1e6f0341d86aed6d00e(4372 次提交)x86_64 hpack-0.15.0

OS: Ubuntu 16.10


看起来是 bug

我发现了一个黑客:

我换了

("C compiler flags", "-fno-PIE -fno-stack-protector")

("C compiler flags", "-fPIC -fno-stack-protector")

在文件中

/home/you/.stack/programs/x86_64-linux/ghc-8.0.1/lib/ghc-8.0.1/settings

现在它可以编译并运行了。我在我的项目中测试了它。

问题在于 Cabal 如何调用 hsc2hs。您需要提交 https://github.com/haskell/cabal/commit/c993a0c6660aa10d8c79ed0cc4961c59acfc91c8,它在 Cabal 1.24.1.0 中存在。