# Ghc can't load a package, even when ghc-pkg listed it

**URL:** <https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573>\
**Category:** Learn\
**Created:** [June 20, 2023, 5:53am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573 "2023-06-20T05:53:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DanEscher98](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/danescher98/32/3291_2.png) [@DanEscher98](https://discourse.haskell.org/u/DanEscher98)\
**Post date:** [June 20, 2023, 5:53am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/1 "2023-06-20T05:53:34Z")

</div>

Reading the [Haskel School of Music](https://www.euterpea.com/haskell-school-of-music/) I was trying to install the needed packages: [Euterpea](https://github.com/Euterpea/Euterpea2), `HSoM` and `UISF`.

I’ve installed all the Haskell toolchain from fresh through `ghcup`. Installing Euterpea with `cabal v2-install --allow-newer --lib` was successful. But when trying to compile HSoM same way it gives an error:

```haskell
Cloning into 'HSoM'...
Wrote tarball sdist to /app/HSoM/dist-newstyle/sdist/HSoM-1.0.0.tar.gz
Resolving dependencies...
Error: cabal: Could not resolve dependencies:
[__0] next goal: Euterpea (user goal)
[__0] rejecting: Euterpea-2.0.7, Euterpea-2.0.6, Euterpea-2.0.5,
Euterpea-2.0.4, Euterpea-2.0.3, Euterpea-2.0.2, Euterpea-2.0.1,
Euterpea-2.0.0, Euterpea-1.1.1, Euterpea-1.1.0, Euterpea-1.0.0 (constraint
from user target requires ==2.0.8)
[__0] fail (backjumping, conflict set: Euterpea)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: Euterpea

```

My guess is that Euterpea is installed and loaded for `ghc`, but not for `cabal`

```bash
$ cabal list --installed | awk '/^\* Euterpea$/,/^$/'
* Euterpea
    Synopsis: Library for computer music research and education
    Default available version: 2.0.7
    Installed versions: 2.0.8
    Homepage: http://www.euterpea.com
    License: BSD3

$ cabal list Euterpea # I don't get why it says "Not Installed"
* Euterpea
    Synopsis: Library for computer music research and education
    Default available version: 2.0.7
    Installed versions: [Not installed]
    Homepage: http://www.euterpea.com
    License: BSD3

$ ghc-pkg list Euterpea
/opt/ghc/9.4.5/lib/ghc-9.4.5/lib/package.conf.d
    (no packages)
/root/.ghc/x86_64-linux-9.4.5/package.conf.d
    Euterpea-2.0.8

```

I’ve double-checked that the versions of `ghc`, `ghci` and `ghc-pkg` matched. As a note, I can `import FRP.UISF` which I installed running `cabal install --lib UISF`. For reproducibility, I wrote this `Dockerfile`. Copy the contents locally and you can test the `Dockerfile` by:

```bash
docker build -t euterpea .
docker run -it euterpea

```

```haskell
# Base image with GHC and required dependencies
FROM haskell:latest

# Install system-level dependencies
RUN apt-get update && apt-get install -y \
    libgmp-dev \
    fluidsynth \
    ffmpeg \
    alsa-utils \
    libasound2-dev

# Set the working directory
WORKDIR /app

RUN cabal update

# HSoM depends on Euterpea and UISF
RUN apt-get install -y \
    libghc-openglraw-dev \
    libghc-gluraw-dev \
    && cabal install --lib UISF

# Clone and install Euterpea2
RUN git clone https://github.com/Euterpea/Euterpea2.git \
    && cd Euterpea2 \
    && cabal v2-install --allow-newer --lib

# Clone and install HSoM
RUN git clone https://github.com/Euterpea/HSoM.git \
    && cd HSoM; mv readme.txt ReadMe.txt \
    && cabal v1-install --allow-newer

# Set the command to start the server or run other application
CMD ["/bin/bash"]

```

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [June 20, 2023, 10:28am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/2 "2023-06-20T10:28:21Z")

</div>

I fear the Haskell School of Music installation guide is woefully outdated. I fairly frequently see questions about trying to build it.

That said, I don’t understand the problem you’re seeing. I can build it fine.

But firstly an important point:

never use `cabal install --lib`!

I know `cabal` itself recommends you try it. Don’t. `cabal` is very naughty to recommend something that causes a huge bunch of headaches. If you ever get tempted to use `cabal install --lib` and you don’t know what to do instead please post a question here.

Now onto actually building it. Here’s what I did:

```haskell
$ git clone https://github.com/Euterpea/HSoM.git
$ cd HSoM
$ cabal build --allow-newer

```

and it built without problems. You _do not have to install dependencies manually_! That means you don’t need to mention `UISF` or `Euterpea` explicitly. `cabal` will just download them from Hackage and install them.

Now, the version of `Euterpea` `cabal` pulled in was `2.0.7` (which is on Hackage) and perhaps you want `2.0.8` (which is not on Hackage) so that makes things slightly more complicated.

But before we get more complicated can we establish a baseline? Please tell me whether you can `cabal build` `HSoM` using the commands I give above?

* * *

FWIW I did have to install the Debian dependencies manually, specifically

```haskell
libglu1-mesa-dev
libasound-dev
libgl-dev

```

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [June 20, 2023, 10:32am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/3 "2023-06-20T10:32:01Z")

</div>

I’ve just noticed this in your `Dockerfile`

> [@DanEscher98](#):
>
> ` && cabal v1-install --allow-newer`

Is there any particular reason you’re using `v1-install` here? Just use `v2-install`! (And in fact `v2-install` is now the default, so just use `install`)

---

<div class="post-metadata">

**Author:** ![DanEscher98](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/danescher98/32/3291_2.png) [@DanEscher98](https://discourse.haskell.org/u/DanEscher98)\
**Post date:** [June 20, 2023, 11:17am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/4 "2023-06-20T11:17:34Z")

</div>

Thanks! Yeah, I was able to build it using your commands. Even though, I still can’t load it from `ghci`. But at the end I learned how to kinda properly configure a project with `package.yaml`. It seems, my initial approach of installing global libraries isn’t the recommended way. I left my config files for future references. `stack new playhsom`

```haskell
# package.yaml

# I left the rest of the default fields
dependencies:
- base >= 4.7 && < 5
- Euterpea >= 2.0.7
- HSoM >= 1.0.0
- random

executables:
  playhsom-exe:
    main: Main.hs
    source-dirs: app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - playhsom
    # Important: if not, ghci complains about duplicate names
    when:        
    - condition: false        
      other-modules: Paths_playhsom

```

```haskell
# stack.yaml

resolver: nightly-2023-06-20

packages:
- .

extra-deps:
  - Euterpea-2.0.7
  - HSoM-1.0.0
  - PortMidi-0.2.0.0
  - UISF-0.4.0.0
  - pure-fft-0.2.0

```

```bash
# Finally run this to star playing with the libraries :)
stack build
stack ghci

```

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [June 20, 2023, 11:21am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/5 "2023-06-20T11:21:02Z")

</div>

> [@DanEscher98](#):
>
> I still can’t load it from `ghci`

Right, in the `cabal` version 2 world you don’t use naked `ghci` anymore. Instead you use `cabal repl`.

> my initial approach of installing global libraries isn’t the recommended way

Correct.

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [June 20, 2023, 11:22am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/6 "2023-06-20T11:22:08Z")

</div>

```haskell
dependencies:
- HSoM >= 1.0.0

```

Oh right, if `HSoM` _itself_ is a dependency of a Stack project then you don’t have to install that manually either! (But you probably worked that out by now.)

---

<div class="post-metadata">

**Author:** ![DanEscher98](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/danescher98/32/3291_2.png) [@DanEscher98](https://discourse.haskell.org/u/DanEscher98)\
**Post date:** [June 20, 2023, 11:31am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/7 "2023-06-20T11:31:59Z")

</div>

Oh I didn’t knew about `cabal repl`. Equivalent to `stack ghci` I guess. Thanks man!

---

<div class="post-metadata">

**Author:** ![tomjaguarpaw](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.haskell.org/tomjaguarpaw/32/1230_2.png) [@tomjaguarpaw](https://discourse.haskell.org/u/tomjaguarpaw)\
**Post date:** [June 20, 2023, 11:35am UTC](https://discourse.haskell.org/t/ghc-cant-load-a-package-even-when-ghc-pkg-listed-it/6573/8 "2023-06-20T11:35:26Z")

</div>

> Equivalent to `stack ghci`

Yes exactly.

You’re welcome! The Haskell community could afford to document these things better so well done on struggling through and you’re welcome to post here any time you’d like a hand with something.
