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

Reading the Haskel School of Music I was trying to install the needed packages: Euterpea, 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:

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

$ 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:

docker build -t euterpea .
docker run -it euterpea
# 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"]

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:

$ 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

libglu1-mesa-dev
libasound-dev
libgl-dev
3 Likes

I’ve just noticed this in your Dockerfile

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)

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

# 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
# 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
# Finally run this to star playing with the libraries :)
stack build
stack 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.

1 Like
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.)

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

1 Like

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.