haskell / haskell/cabal

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

Open
#7,186 4 comments 0 reactions 0 assignees View on GitHub
Cabal: code-coverage type: bug
Dominant language
Haskell
Stars
1.7k
Forks
750
Avg merge
4d 3h
Merged PRs (30d)
28

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.