I am building a Haskell library with Cabal, and want to use this library in some other Cabal projects.
The problem is that after installing the library (with Cabal),
my library is not available to the other Cabal projects.
Neither ghc-pkg list
nor cabal list
shows my library
(and also does not show packages that my library depends on but
was downloaded by cabal as part of the build of my library).
How do I make cabal find my library when building the dependent projects?
I am using Linux, but the same problem has been reported for Windows.
My setup:
- Linux (Debian 11.5)
- Haskell installed by
ghcup
:- ghc 8.0.2
- cabal 3.6.2
(My library and the other projects need this version of ghc.)
My library builds and installs without problems using
$ cabal build
$ cabal install --lib
But ghc-pkg list
and cabal list --installed
both show only the
"predefined" libraries that was installed before the build.
These are found in ~/.ghcup/ghc/8.0.2/lib/ghc-8.0.2/package.conf.d/
.
My library, and the libraries that it depends on, are installed in
~/.cabal/store/ghc-8.0.2/package.db/
. But cabal
doesn't find them
when building my other dependent projects.
I have tried different options for building, all with the same result of
Resolving dependencies...
cabal: Could not resolve dependencies:
[__0] trying: <PRJ-USING-LIB> (user goal)
[__1] unknown package: wilde (dependency of <PRJ-USING-LIB>)
[__1] fail (backjumping, conflict set: <PRJ-USING-LIB>, <MY-LIB>)
After searching the rest of the dependency tree exhaustively, these were the
goals I've had most trouble fulfilling: <PRJ-USING-LIB>, <MY-LIB>
The options I tried are:
cabal build --global
cabal build --user
cabal build --package-db=~/.cabal/store/ghc-8.0.2/package.db
Interestingly, when adding ghc-options: -L<PATH-TO-MY-LIB-SRC>
to the
dependent projects cabal file, cabal build
says that my library is hidden:
...
Warning: Instead of 'ghc-options: -L<PATH-TO-MY-LIB-SRC>' use
'extra-lib-dirs: <PATH-TO-MY-LIB-SRC>'
...
app/Main.hs:3:1: error:
Failed to load interface for ‘<MODULE-IN-MY-LIB>’
It is a member of the hidden package ‘<MY-LIB>-0.5’.
Perhaps you need to add ‘<MY-LIB>’ to the build-depends in your .cabal file.
Use -v to see a list of the files searched for.
But trying to ghc-pkg expose <MY-LIB>
, it says that
it cannot find .