14

I'm using a VM with the following configuration:

  • Arch Linux (3.0-ARCH kernel)
  • GHC 7.0.3
  • cabal-install 0.10.2
  • Cabal library 1.10.1.0

When I try to build zlib using cabal...

$ cabal install zlib

I get the following output:

Resolving dependencies...
Downloading zlib-0.5.3.2...
Configuring zlib-0.5.3.2...
Preprocessing library zlib-0.5.3.2...
Stream.hsc:86:21: error: missing binary operator before token "("
Stream.hsc: In function ‘main’:
Stream.hsc:86:21: error: missing binary operator before token "("
Stream.hsc:86:21: error: missing binary operator before token "("
compiling dist/build/Codec/Compression/Zlib/Stream_hsc_make.c failed (exit code 1)
command was: /usr/bin/gcc -c dist/build/Codec/Compression/Zlib/Stream_hsc_make.c -o dist/build/Codec/Compression/Zlib/Stream_hsc_make.o -fno-stack-protector -fno-stack-protector -D__GLASGOW_HASKELL__=700 -Dlinux_BUILD_OS -Dlinux_HOST_OS -Dx86_64_BUILD_ARCH -Dx86_64_HOST_ARCH -I/usr/lib/ghc-7.0.3/bytestring-0.9.1.10/include -I/usr/lib/ghc-7.0.3/base-4.3.1.0/include -I/usr/lib/ghc-7.0.3/include -I/usr/lib/ghc-7.0.3/include -I/usr/lib/ghc-7.0.3/include/
cabal: Error: some packages failed to install:
zlib-0.5.3.2 failed during the building phase. The exception was:
ExitFailure 1

Can anyone shed some light on this build error?


Edit: Here's a snippet from Stream.hsc with line numbers:

 82 import Foreign
 83          ( Word8, Ptr, nullPtr, plusPtr, peekByteOff, pokeByteOff, mallocBy    tes  
 84          , ForeignPtr, FinalizerPtr, newForeignPtr_, addForeignPtrFinalizer
 85          , withForeignPtr, touchForeignPtr )
 86 #if MIN_VERSION_base(4,4,0)
 87 import Foreign.ForeignPtr.Unsafe ( unsafeForeignPtrToPtr )
 88 import System.IO.Unsafe          ( unsafePerformIO )
 89 #else
 90 import Foreign ( unsafeForeignPtrToPtr, unsafePerformIO )
 91 #endif
Jon Nadal
  • 729
  • 9
  • 14

5 Answers5

12

On Ubuntu, I fixed (or really, avoided) a similar error with

sudo apt-get install libghc-zlib-dev  libghc-zlib-bindings-dev

(I don't know if both are needed.)

poolie
  • 9,289
  • 1
  • 47
  • 74
11

For some reason, the MIN_VERSION_base macro doesn't get expanded, thus the preprocessor sees the condition MIN_VERSION_base(4,4,0) which it of course cannot handle. I've not yet found out why the macro isn't expanded, but workarounds are

  1. install zlib-0.5.3.1 instead
  2. unpack the tarball and edit Codec/Compression/Zlib/Stream.hsc to remove the offending macro (you're using 7.0.3, so your base version is 4.3.1.0, you can replace the macro with 0)

Edit: After poking around a bit, I found out that to hide these preprocessor directives, which aren't intended for hsc2hs to process, they have to be masked by an extra '#'. Bug report underway.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
  • Hah, it's funny, I ran into the exact same problem today :) – Phyx Jan 22 '12 at 20:58
  • 1
    @Phyx proper solution found, should not be long until it reaches hackage. – Daniel Fischer Jan 22 '12 at 21:13
  • Note that cabal-install from HEAD (due to be 0.14, although it might be in 0.12 as well, I'm not sure) does pass these macros to hsc2hs. This is probably how the bug got introduced: whoever added the macros, had a development version of cabal-install. – Erik Hesselink Feb 02 '12 at 07:35
  • Yes, sorry folks. I tested with several ghc versions but seems I was using a recent Cabal lib version with every ghc version I used. I've fixed it and uploaded a new version. – Duncan Coutts Feb 07 '12 at 00:45
6

I'm still encountering this with the haskell package zlib-0.5.4.2 on GHC 7.8.4. I think the issue is a non-standard location of the library. I solved it by hand-installing zlib 1.2.8 and then doing:

cabal install zlib --extra-lib-dirs=/usr/local/lib --extra-include-dir=/usr/local/include
nont
  • 9,322
  • 7
  • 62
  • 82
  • That fixed it for me. Thanks! In particular, these can be added in `~/.cabal/config`. –  Mar 25 '15 at 17:12
2

The most likely reason is that the zlib C library headers are missing on your machine. You might instead try to use the Arch Linux "Haskell Platform" or haskell-zlib packages, which resolve C dependencies for you.

Don Stewart
  • 137,316
  • 36
  • 365
  • 468
  • Thank you for the suggestions. Unfortunately, both the **extra/haskell-platform** (2011.2.0.0-4) and **extra/haskell-zlib** (0.5.3.1-2.1) packages are already installed. Really all I've done in the VM is **sudo pacman -S haskell-platform && cabal install virthualenv && mkdir -p src/proj && cd src/proj && virthualenv && source .virthualenv/bin/activate && cabal install yesod**. The yesod build broke due to zlib error. – Jon Nadal Jan 22 '12 at 15:20
  • I got the exact same message, and I've got the zlib C library headers present. Adding the missing # made it work. – L. Kolmodin Jan 28 '12 at 09:34
2

I don't understand this error, but it happened to me also earlier today while trying to install Agda 2.3 using GHC 7.4. Saizan from #agda suggested that I try

cabal unpack zlib
cd zlib-0.5.3.2/
runghc Setup configure --user; runghc Setup build; runghc Setup install

This proved effective. But I'm still in the dark about what's actually the problem.

Still, as it worked, I thought I'd share.

poolie
  • 9,289
  • 1
  • 47
  • 74
pigworker
  • 43,025
  • 18
  • 121
  • 214
  • Thank you for sharing. I ran the suggested commands but got the same error when performing **runghc Setup build**. I've updated my question to include a snippet from Stream.hsc. – Jon Nadal Jan 22 '12 at 17:57
  • 1
    +1 because this solution works *after* updating Stream.hsc as suggested by Daniel Fischer – Jon Nadal Jan 23 '12 at 02:50
  • @JonNadal does the answer need to be updated to indicate you should edit it before running? – poolie Jan 29 '12 at 07:20
  • @poolie It's up to you. Daniel's solution is correct; this one just provides some helpful follow-up. To clarify what needs to be done before performing **runghc**: (1) determine base version: **cabal info base|grep 'Versions installed:'** (2) If version >= 4.4.0, change **#if MIN_VERSION_base(4,4,0)** to **#if 1**. Otherwise, change it to **#if 0**. – Jon Nadal Jan 30 '12 at 13:17
  • @poolie, I should have also mentioned that Stream.hsc is located at Codec/Compression/Zlib/Stream.hsc in the zlib directory. – Jon Nadal Jan 30 '12 at 13:25