Skip to content

Instantly share code, notes, and snippets.

@chris-martin chris-martin/zlib.md
Last active May 23, 2018

Embed
What would you like to do?

The problem:

chris@cubby ~ ❯❯❯ nix run -f '<nixpkgs>' zlib -c cabal install zlib
Resolving dependencies...
Configuring zlib-0.6.2...
Failed to install zlib-0.6.2
Build log ( /home/chris/.cabal/logs/ghc-8.2.2/zlib-0.6.2-L2Qec9Buml21zwTs2VzSGb.log ):
cabal: Entering directory '/tmp/cabal-tmp-31070/zlib-0.6.2'
Configuring zlib-0.6.2...
cabal: Missing dependency on a foreign library:
* Missing (or bad) header file: zlib.h
* Missing C library: z
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
cabal: Leaving directory '/tmp/cabal-tmp-31070/zlib-0.6.2'
cabal: Error: some packages failed to install:
zlib-0.6.2-L2Qec9Buml21zwTs2VzSGb failed during the configure step. The
exception was:
ExitFailure 1

The requirement of zlib.h is declared here: https://github.com/haskell/zlib/blob/964a80a5451f4dd4244f9a86221fe2b4cb4bff2a/zlib.cabal#L74

The doc for the includes attibute https://www.haskell.org/cabal/users-guide/developing-packages.html#pkg-field-includes

A list of header files to be included in any compilations via C. This field applies to both header files that are already installed on the system and to those coming with the package to be installed. The former files should be found in absolute paths, while the latter files should be found in paths relative to the top of the source tree or relative to one of the directories listed in include-dirs.

However, the Cabal documentation (this part, at least) neglects to mention what "absolute paths" the files are to be "found" in, so I am now stuck.

https://stackoverflow.com/questions/50479521/where-does-cabal-search-for-includes-files

@KirinDave

This comment has been minimized.

Copy link

commented May 23, 2018

pulling in zlib.dev and pkgconfig seems to fix the header issue. However, not the binary issue. The zlib build in Cabal does support pkgconfig. From my cabal.project.freeze:

zlib ==0.6.2,
zlib -pkg-config -non-blocking-ffi

It's notable that most other libraries work, so something seems specific to zlib here.

@KirinDave

This comment has been minimized.

Copy link

commented May 23, 2018

More info:

I note that libz is indeed in my environment using cabal new-build -v3:

("NIX_LDFLAGS","-rpath /nix/store/b9hzlfkcbfnrgqj00mhd42pfqz7yjvwf-shell/lib64 -rpath /nix/store/b9hzlfkcbfnrgqj00mhd42pfqz7yjvwf-shell/lib 
 -L/nix/store/akg4ibk3xr92y3hwrx30k2ag6nzvyvk8-postgresql-9.6.7/lib -L/nix/store/ysx12ay7qd8cvaf5k575zyhpqp35ifi3-postgresql-9.6.7-lib/lib -L/nix/store/j0y15xvm86w71508pk7iywnac474zrpc-zlib-1.2.11-dev/lib -L/nix/store/dl66jvc19im9lqslzqsz
sp2gif2y0y8i-zlib-1.2.11/lib")

However, it doesn't seem to actually get propagated to build commands:

Using pkg-config version 0.29.2 found on system at:
/nix/store/hqing82mi40rvfxp6c1q8ghc89z8630z-pkg-config-0.29.2/bin/pkg-config
Using runghc version 8.2.2 found on system at:
/home/ash/.nix-profile/bin/runghc
Using strip version 2.28 found on system at:
/nix/store/klwxxrlgalq49cjnczvgha3j7l00jixw-binutils-2.28.1/bin/strip
Using tar found on system at:
/nix/store/0lyn8v4w3cd70hzg5md0xwhykhlbsq9f-gnutar-1.29/bin/tar
No uhc found
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc -fno-stack-protector /run/user/1000/17149-4.c -o /run/user/1000/17149-5 '-D__GLASGOW_HASKELL__=802' '-Dlinux_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Dlinux_HOST_OS=1' '-Dx86_64_HOST_ARCH=1' -Idist/build/autogen -I. -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2/include -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0/include -I/nix/store/zi1rbssjvyyddjd4s8jmbardz11akd0s-gmp-6.1.2-dev/include -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0/include -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/include -lz -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/deepseq-1.4.3.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/array-0.5.2.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0 -L/nix/store/83abj589v6z6qak2rxlb9vvynnfvnrzg-gmp-6.1.2/lib -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/ghc-prim-0.5.1.1 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/rts
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc returned
ExitFailure 1 with error message:
/nix/store/mdyy001q67hiks0g24ra53z7ckm4jfr4-binutils-2.28.1/bin/ld: cannot
find -lz
collect2: error: ld returned 1 exit status
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc -fno-stack-protector /run/user/1000/17149-6.c -o /run/user/1000/17149-7 -lz -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/deepseq-1.4.3.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/array-0.5.2.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0 -L/nix/store/83abj589v6z6qak2rxlb9vvynnfvnrzg-gmp-6.1.2/lib -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/ghc-prim-0.5.1.1 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/rts
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc returned
ExitFailure 1 with error message:
/nix/store/mdyy001q67hiks0g24ra53z7ckm4jfr4-binutils-2.28.1/bin/ld: cannot
find -lz
collect2: error: ld returned 1 exit status
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc -fno-stack-protector /run/user/1000/17149-8.c -o /run/user/1000/17149-9 -lz -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/deepseq-1.4.3.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/array-0.5.2.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0 -L/nix/store/83abj589v6z6qak2rxlb9vvynnfvnrzg-gmp-6.1.2/lib -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/ghc-prim-0.5.1.1 -L/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/rts
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc returned
ExitFailure 1 with error message:
/nix/store/mdyy001q67hiks0g24ra53z7ckm4jfr4-binutils-2.28.1/bin/ld: cannot
find -lz
collect2: error: ld returned 1 exit status
/nix/store/6s3dl13ingr21z93dy6zxcc652wdlcrh-gcc-wrapper-6.4.0/bin/cc -fno-stack-protector /run/user/1000/17149-10.c -o /run/user/1000/17149-11 -c '-D__GLASGOW_HASKELL__=802' '-Dlinux_BUILD_OS=1' '-Dx86_64_BUILD_ARCH=1' '-Dlinux_HOST_OS=1' '-Dx86_64_HOST_ARCH=1' -Idist/build/autogen -I. -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/bytestring-0.10.8.2/include -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/base-4.10.1.0/include -I/nix/store/zi1rbssjvyyddjd4s8jmbardz11akd0s-gmp-6.1.2-dev/include -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/integer-gmp-1.0.1.0/include -I/nix/store/aw9d5y8d26hp573didjmmz9kvqdark4l-ghc-8.2.2/lib/ghc-8.2.2/include
CallStack (from HasCallStack):
  die', called at ./Distribution/Simple/Configure.hs:1798:34 in Cabal-2.2.0.1-L9Ga2UhvKMG4igUBTXMz2l:Distribution.Simple.Configure
  checkForeignDeps, called at ./Distribution/Simple.hs:615:7 in Cabal-2.2.0.1-L9Ga2UhvKMG4igUBTXMz2l:Distribution.Simple
cabal: Missing dependency on a foreign library:
* Missing (or bad) C library: z
@chris-martin

This comment has been minimized.

Copy link
Owner Author

commented May 23, 2018

I still have no success here.

chris@cubby ~ ❯❯❯ nix run -f '<nixpkgs>' pkgconfig zlib.dev -c cabal install --flags=pkg-config zlib
Resolving dependencies...
Configuring zlib-0.6.1.2...
Failed to install zlib-0.6.1.2
Build log ( /home/chris/.cabal/logs/ghc-8.2.2/zlib-0.6.1.2-7l4jONkcXpfEPtSdExuGol.log ):
cabal: Entering directory '/tmp/cabal-tmp-13824/zlib-0.6.1.2'
Configuring zlib-0.6.1.2...
cabal: Missing dependency on a foreign library:
* Missing (or bad) header file: zlib.h
* Missing C library: z
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
cabal: Leaving directory '/tmp/cabal-tmp-13824/zlib-0.6.1.2'
cabal: Error: some packages failed to install:
zlib-0.6.1.2-7l4jONkcXpfEPtSdExuGol failed during the configure step. The
exception was:
ExitFailure 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.