4

I am building a Haskell library with Cabal that I would like to install to use in some other projects. I am using Windows PowerShell and new style Cabal commands. I have ghc 8.10.1 and Cabal 3.2.0.0 and used Chocolatey to install them. cabal new-install --lib builds and installs the library just fine and without warnings. From --verbose output I noticed that Cabal mentions folder C:\Users\Liisi\AppData\Roaming\cabal\store\ghc-8.10.1\package.db and it does contain my package.

However, when I try to compile a test project that consists of a single Haskell file that uses this library, ghc can't find the library. (The test project is not itself a Cabal project since I intend to use the library for tiny, mostly single-file projects.)

ghc Test.hs and ghc --make Test.hs both fail to find the library. ghc-pkg list does not list the name of my library. In another question (which was probably the wrong question to ask) I got the suggestion to try ghc -package-env=C:\Users\Liisi\.ghc\x86_64-mingw32-8.10.1\environments\default --make and this one does work - however, it would defeat the main purpose of making the library a Cabal project (convenience and usability).

I've also had an opportunity to test my package on OSX and everything worked as expected. So it's probably a Windows-specific issue.

Liisi
  • 329
  • 1
  • 6
  • There seems to be a recurrent problem that `cabal new-install --lib` writes a package environment file in a *global* default location, but that environment isn't picked up afterwards by ghc and ghci according to the package environment search rules https://downloads.haskell.org/ghc/latest/docs/html/users_guide/packages.html Does the workaround of creating a *local* package environment file, described here https://stackoverflow.com/questions/62422191/how-to-find-and-use-quickcheck-package-since-i-forgot-to-use-lib-while-doing-c#comment110435320_62422191 work? – danidiaz Jul 01 '20 at 19:55
  • @danidiaz It does work. However, it's not a nice workaround. It kind of defeats the purpose of a package - to install it once when it is changed, without thinking about every project that depends on it. If I wanted a workaround, I'd just add a -i flag and a relative path to the library source when compiling the test project. – Liisi Jul 02 '20 at 16:35
  • 1
    @danidiaz I'd like to understand what I'm doing wrong. I just now discovered another issue with cabal new-install. When I use it to install my own library and then any other unrelated one (like QuickCheck or megaparsec, for example), I get a conflict. ```Could not resolve dependencies: [__0] unknown package: aoide (user goal)```. (aoide is the name of my music package.) I can install external libraries again after deleting ```Users/Liisi/AppData/Roaming/cabal```. – Liisi Jul 02 '20 at 17:00

0 Answers0