1

When I run

stack --resolver=lts-7.14 install zlib

I'm getting message saying that package should be recompiled with -fPIC flag:

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

How to tell stack to recompile zlib with -fPIC flag?


I added ghc-options to yaml file:

ghc-options:
  zlib: -fPIC

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

Also, I added -fPIC flag to ghc-options in cabal file.

But still, I'm getting the same output:

--  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

Where ghc-options are -ddump-hi and -ddump-to-file and no -fPIC. Did I miss something?


GCC, stack and OS versions:

GCC: gcc (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005

Stack: Version 1.3.0, Git revision 99b910d3c8e183aa376cb1e6f0341d86aed6d00e (4372 commits) x86_64 hpack-0.15.0

OS: Ubuntu 16.10


Looks like it is bug.

I found a hack:

I replaced

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

by

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

in file

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

Now it compiles and works. I tested it on my project.

4
  • Try --ghc-options -fPIC, and/or check the stack FAQ. Commented Dec 28, 2016 at 16:25
  • 1
    Possibly related What stack / gcc version you are using, and what OS? Commented Dec 28, 2016 at 17:30
  • @MichaelFoukarakis updated question Commented Dec 28, 2016 at 17:34
  • @ppb indeed, I found hack there: changing ghc settings in .stack from ("C compiler flags", "-fno-PIE -fno-stack-protector") to ("C compiler flags", "-fPIC -fno-stack-protector"). Commented Dec 28, 2016 at 19:43

1 Answer 1

0

The issue is in how Cabal invokes hsc2hs. You need commit https://github.com/haskell/cabal/commit/c993a0c6660aa10d8c79ed0cc4961c59acfc91c8 which is present as of Cabal 1.24.1.0.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.