haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.58k stars 685 forks source link

Error while loading shared libraries with v2-run --enable-coverage #7186

Open wolfgangwalther opened 3 years ago

wolfgangwalther commented 3 years ago

Describe the bug Executable built and run with v2-run --enable-coverage --enable-executable-dynamic can't find library.

To Reproduce Set up a sample project with cabal init --interactive. Select "Library and Executable", everything else as default.

Executable name is "example".

$ cabal v2-run --enable-coverage --enable-executable-dynamic example
[...]/example/dist-newstyle/build/x86_64-linux/ghc-8.10.2/example-0.1.0.0/build/example/example: error while loading shared libraries: libHSexample-0.1.0.0-inplace-ghc8.10.2.so: cannot open shared object file: No such file or directory

The same works just fine without --enable-coverage.

Expected behavior No error, but "Hello, Haskell!" :)

System information Arch Linux with:

$ cabal --version
cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library

$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 8.10.2

Additional context

libHSexample-0.1.0.0-inplace-ghc8.10.2.so is built correctly and in the same path as without --enable-coverage. When I set LD_LIBRARY_PATH manually to this folder, everything works fine.

The exact same behaviour is shown with v2-build + v2-exec, but the latter allows to peek a bit into the environment that cabal creates with v2-run and v2-exec:

I ran cabal v2-exec sh -- -c 'echo $LD_LIBRARY_PATH', but LD_LIBRARY_PATH is unset in both cases - with and without coverage enabled (on both build and exec). I'm not sure what that means, without this path set I would expect v2-exec without coverage enabled to fail as well - but it does not.

Running cabal v2-exec sh -- -c 'echo $PATH' with and without --enable-coverage (again on both build and exec) confirms, that $PATH is set correctly. Obviously, because otherwise the executable would not be found.

Should v2-run / v2-exec also set LD_LIBRARY_PATH for dynamic builds?

fgaz commented 3 years ago

Cannot reproduce on nixos, with cabal 3.2.0.0 and ghc 8.8.4. Arch Linux's packaging strikes again? :-/

From their docs it looks like you also need a bunch of other configs

wolfgangwalther commented 3 years ago

I do have the arch-recommended config in place. However, I just reproduced it on my host system (Arch) - it first came up in a project in nix-shell. I just confirmed the same behaviour with nix-shell --pure. I also removed my ~/.cabal folder with config etc. before. I think that rules out the Arch package - or did I miss anything?

In nix-shell it's currently:

The Glorious Glasgow Haskell Compilation System, version 8.8.3

and

cabal-install version 3.2.0.0
compiled using version 3.2.0.0 of the Cabal library
wolfgangwalther commented 3 years ago

And... I just confirmed the same thing in a docker container running the same nix-shell but on top of a nixos docker image. Definitely without relation to Arch.

wolfgangwalther commented 1 month ago

FTR: Just confirmed this is still the same with cabal 3.10.3.0 and GHC 9.10.1 (via ghcup)