Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Haskell Z3 package can't find libz3.dylib at run-time on Darwin #16357

Closed
kalhauge opened this issue Jun 20, 2016 · 9 comments
Closed

Haskell Z3 package can't find libz3.dylib at run-time on Darwin #16357

kalhauge opened this issue Jun 20, 2016 · 9 comments
Assignees
Labels
0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: haskell

Comments

@kalhauge
Copy link
Contributor

Issue description

There seem to be a linking bug, while trying to compile the z3 haskell package. It seams like the language is correctly loaded, but the versions between the z3 haskell package and the z3 library might have diverted. The interesting error is:

dyld: Library not loaded: libz3.dylib
  Referenced from: /private/var/folders/gh/j563xb_s475dmjn_5n60bwnw0000gn/T/nix-build-z3-4.1.0.drv-0/z3-4.1.0/dist/build/Z3/Base/C_hsc_make
  Reason: image not found
running dist/build/Z3/Base/C_hsc_make failed (exit code -5)

Even though, that the included library does contain libz3.dylib.
--extra-lib-dirs=/nix/store/k3pbd2znh0yiq7hw7hg4k50gp474g1xc-z3-4.4.1/lib

Thank you very much for looking into it.

Steps to reproduce

nix-build --expr "(import <nixpkgs> {}).haskellPackages.ghcWithPackages (p: [ p.z3 ])"
these derivations will be built:
  /nix/store/vgvi8rbhicvq2n9nnjy5yr85cigaisnn-z3-4.1.0.drv
  /nix/store/xlxhqqp7fi0vpj1s4krvbw2xk57kyai0-ghc-7.10.3.drv
building path(s) ‘/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0’
setupCompilerEnvironmentPhase
Build with /nix/store/g2xpd8z4drs9ylahrc28hc29y12a8isq-ghc-7.10.3.
unpacking sources
unpacking source archive /nix/store/lvq9b60p58x66b57ar9gm92j0f839zx5-z3-4.1.0.tar.gz
source root is z3-4.1.0
setting SOURCE_DATE_EPOCH to timestamp 1437254814 of file z3-4.1.0/z3.cabal
patching sources
compileBuildDriverPhase
setupCompileFlags: -package-db=/private/var/folders/gh/j563xb_s475dmjn_5n60bwnw0000gn/T/nix-build-z3-4.1.0.drv-0/package.conf.d -j4 -threaded
[1 of 1] Compiling Main             ( Setup.hs, /private/var/folders/gh/j563xb_s475dmjn_5n60bwnw0000gn/T/nix-build-z3-4.1.0.drv-0/Main.o )
Linking Setup ...
configuring
configureFlags: --verbose --prefix=/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --with-gcc=clang --package-db=/private/var/folders/gh/j563xb_s475dmjn_5n60bwnw0000gn/T/nix-build-z3-4.1.0.drv-0/package.conf.d --ghc-option=-optl=-Wl,-headerpad_max_install_names --disable-split-objs --disable-library-profiling --disable-executable-profiling --enable-shared --enable-library-vanilla --enable-executable-dynamic --enable-tests --extra-include-dirs=/nix/store/k3pbd2znh0yiq7hw7hg4k50gp474g1xc-z3-4.4.1/include --extra-lib-dirs=/nix/store/k3pbd2znh0yiq7hw7hg4k50gp474g1xc-z3-4.4.1/lib
Configuring z3-4.1.0...
Flags chosen: examples=False
Dependency QuickCheck >=2.5.1: using QuickCheck-2.8.2
Dependency base >=4.5 && <5: using base-4.8.2.0
Dependency containers -any: using containers-0.5.6.2
Dependency hspec >=2.1: using hspec-2.2.3
Dependency mtl >2.1: using mtl-2.2.1
Dependency z3 ==4.*: using z3-4.1.0
Using Cabal-1.22.5.0 compiled by ghc-7.10
Using compiler: ghc-7.10.3
Using install prefix: /nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0
Binaries installed in:
/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0/bin
Libraries installed in:
/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0/lib/ghc-7.10.3/z3-4.1.0
Private binaries installed in:
/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0/libexec
Data files installed in:
/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0/share/x86_64-osx-ghc-7.10.3/z3-4.1.0
Documentation installed in:
/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0/share/doc/x86_64-osx-ghc-7.10.3/z3-4.1.0
Configuration files installed in:
/nix/store/k5cp9kn4hhn5n77q4ginz8xa1i616y3w-z3-4.1.0/etc
No alex found
Using ar found on system at:
/nix/store/shgq0ci2b3x36bzgizg1dz2j6fgh16wj-cctools-binutils-darwin/bin/ar
No c2hs found
No cpphs found
Using gcc version 4.2.1 given by user at:
/nix/store/hswsdaxabvxj4nvlcnl6dxhmsxl7d80c-clang-wrapper-3.7.1/bin/clang
Using ghc version 7.10.3 found on system at:
/nix/store/g2xpd8z4drs9ylahrc28hc29y12a8isq-ghc-7.10.3/bin/ghc
Using ghc-pkg version 7.10.3 found on system at:
/nix/store/g2xpd8z4drs9ylahrc28hc29y12a8isq-ghc-7.10.3/bin/ghc-pkg
No ghcjs found
No ghcjs-pkg found
No greencard found
Using haddock version 2.16.1 found on system at:
/nix/store/g2xpd8z4drs9ylahrc28hc29y12a8isq-ghc-7.10.3/bin/haddock
No happy found
Using haskell-suite found on system at: haskell-suite-dummy-location
Using haskell-suite-pkg found on system at: haskell-suite-pkg-dummy-location
No hmake found
Using hpc version 0.67 found on system at:
/nix/store/g2xpd8z4drs9ylahrc28hc29y12a8isq-ghc-7.10.3/bin/hpc
Using hsc2hs version 0.67 found on system at:
/nix/store/g2xpd8z4drs9ylahrc28hc29y12a8isq-ghc-7.10.3/bin/hsc2hs
Using hscolour version 1.24 found on system at:
/nix/store/kakbxxxzh1xmgyhdhs7zg2qy46w2nmaa-hscolour-1.24/bin/HsColour
No jhc found
Using ld found on system at:
/nix/store/hswsdaxabvxj4nvlcnl6dxhmsxl7d80c-clang-wrapper-3.7.1/bin/ld
No lhc found
No lhc-pkg found
No pkg-config found
Using strip found on system at:
/nix/store/shgq0ci2b3x36bzgizg1dz2j6fgh16wj-cctools-binutils-darwin/bin/strip
Using tar found on system at:
/nix/store/ji5n4m0072a7n60d909jcbd3138cdl7r-gnutar-1.28/bin/tar
No uhc found
building
Building z3-4.1.0...
Preprocessing library z3-4.1.0...
dyld: Library not loaded: libz3.dylib
  Referenced from: /private/var/folders/gh/j563xb_s475dmjn_5n60bwnw0000gn/T/nix-build-z3-4.1.0.drv-0/z3-4.1.0/dist/build/Z3/Base/C_hsc_make
  Reason: image not found
running dist/build/Z3/Base/C_hsc_make failed (exit code -5)
command was: dist/build/Z3/Base/C_hsc_make  >dist/build/Z3/Base/C.hs
builder for ‘/nix/store/vgvi8rbhicvq2n9nnjy5yr85cigaisnn-z3-4.1.0.drv’ failed with exit code 1
cannot build derivation ‘/nix/store/xlxhqqp7fi0vpj1s4krvbw2xk57kyai0-ghc-7.10.3.drv’: 1 dependencies couldn't be built
error: build of ‘/nix/store/xlxhqqp7fi0vpj1s4krvbw2xk57kyai0-ghc-7.10.3.drv’ failed

Technical details

  • System: (NixOS: nixos-version, Ubuntu/Fedora: lsb_release -a, ...)
$  sw_vers
ProductName:    Mac OS X
ProductVersion: 10.11.5
BuildVersion:   15F34
  • Nix version: (run nix-env --version)
    nix-env (Nix) 1.11.2
  • Nixpkgs version: (run nix-instantiate --eval '<nixpkgs>' -A lib.nixpkgsVersion)
    "16.09pre83147.df89584"
@gebner gebner added 0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: haskell labels Jun 20, 2016
@kalhauge
Copy link
Contributor Author

I have created a pull-request with a fix. Temporarily anyone interested can use this snippet to fix it in their config.nix file (in $HOME/.nixpkg/config.nix).

{
packageOverrides = let
  z3hsk =
    { mkDerivation, base, containers, hspec, mtl, QuickCheck, stdenv, z3}:
    mkDerivation {
      pname = "z3";
      version = "4.1.0";
      sha256 = "1vpmwizxcab1mlz7vp3hp72ddla7805jn0lq60fmkjgmj95ryvq9";
      isLibrary = true;
      isExecutable = true;
      libraryHaskellDepends = [ base containers mtl ];
      librarySystemDepends = [ z3 ];
      testHaskellDepends = [ base hspec QuickCheck ];
      preBuild = ''
        export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${z3}/lib
      '';
      homepage = "http://bitbucket.org/iago/z3-haskell";
      description = "Bindings for the Z3 Theorem Prover";
      license = stdenv.lib.licenses.bsd3;
    };
in super: let
  self = super.pkgs;
  z3 = self.haskellPackages.callPackage z3hsk { z3 = super.z3; };
in {
  myHaskellEnv = self.haskellPackages.ghcWithPackages
    ( p: with p;
      [ cabal-install 
        z3
      # ...ect
      ]
    );
};
}

@peti
Copy link
Member

peti commented Sep 10, 2016

With #17145 merged to master, this issue should now be fixed.

@peti peti closed this as completed Sep 10, 2016
@kalhauge
Copy link
Contributor Author

It turns out that my changes did not work. Even though it enables the library to compile it, the environment variable DYLD_LIBRARY_PATH is needed when running the library too.

The example shows running without and with DYLD_LIBRARY_PATH pointing to z3:

$ nix-shell --expr "(import <nixpkgs> {}).haskellPackages.ghcWithPackages (p: [ p.z3 ])"

[nix-shell:~]$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Prelude> import Z3.Base
Prelude Z3.Base> mkConfig
can't load .so/.DLL for: /nix/store/cirafgq3iid29ksgh0aycx09kkqnykr6-z3-4.1.0/lib/ghc-8.0.1/z3-4.1.0/libHSz3-4.1.0-KgyQuPAwO0AFVtoTtjqdwA-ghc8.0.1.dylib (dlopen(/nix/store/cirafgq3iid29ksgh0aycx09kkqnykr6-z3-4.1.0/lib/ghc-8.0.1/z3-4.1.0/libHSz3-4.1.0-KgyQuPAwO0AFVtoTtjqdwA-ghc8.0.1.dylib, 5): Library not loaded: libz3.dylib
  Referenced from: /nix/store/cirafgq3iid29ksgh0aycx09kkqnykr6-z3-4.1.0/lib/ghc-8.0.1/z3-4.1.0/libHSz3-4.1.0-KgyQuPAwO0AFVtoTtjqdwA-ghc8.0.1.dylib
  Reason: image not found)
Prelude Z3.Base>
Leaving GHCi.

[nix-shell:~]$ export DYLD_LIBRARY_PATH=/nix/store/09397r5xi2ynv2hmqy062frjj4bqmwl8-z3-4.4.1/lib

[nix-shell:~]$ ghci
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
Prelude> import Z3.Base
Prelude Z3.Base> mkConfig
Prelude Z3.Base>
Leaving GHCi.

@kalhauge
Copy link
Contributor Author

@peti could you reopen this issue.

@peti peti changed the title Z3 haskell package not installing correctly. Haskell Z3 package can't find libz3.dylib at run-time on Darwin Sep 22, 2016
@peti
Copy link
Member

peti commented Sep 22, 2016

I believe this is a bug in Cabal. Cabal has all the information it needs to make things work, but apparently fails to do so.

@peti peti reopened this Sep 22, 2016
shlevy added a commit to shlevy/nixpkgs that referenced this issue Nov 17, 2016
…yld"

This fix doesn't actually fix the cabal bug (see NixOS#16357), but it does
cause other bugs (see NixOS#20476)

Fixes NixOS#20476

This reverts commit b89fa5f, reversing
changes made to e4b146b.
@domenkozar
Copy link
Member

#21215 seems to be a duplicate of this.

@domenkozar
Copy link
Member

Since 19e2e72 (cc @LnL7) this builds correctly, but fails in check phase:

Linking dist/build/spec/spec ...
running tests
Running 1 test suites...
Test suite spec: RUNNING...
dyld: Library not loaded: libz3.dylib
  Referenced from: /private/var/folders/v0/ydgx93x96375ws14_16p93gr0000gq/T/nix-build-z3-4.1.0.drv-0/z3-4.1.0/dist/build/spec/spec
  Reason: image not found
Test suite spec: FAIL
Test suite logged to: dist/test/z3-4.1.0-spec.log
0 of 1 test suites (0 of 1 test cases) passed.

We may tweak the workaround to also work there, but I'm hoping to get information upstream and fix this also for stack projects using Nix: haskell/cabal#2255 (comment)

@LnL7
Copy link
Member

LnL7 commented Jan 3, 2017

Yeah I still have to look into that, that only patches the ghc dyld so I might just have to do the same for the test binary.

@domenkozar
Copy link
Member

@LnL7 I might have found a way for fix this, wait a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: haskell
Projects
None yet
Development

No branches or pull requests

5 participants