Hi Simon,
The direct answer to your particular problem is that cabal-install-3.10.1 (which you're using) does not add `base` in the package environment created by `install --lib` by default.
So, to fix the problem you'd need to say `cabal install --lib base hashtables primitive` instead.
Better yet, you could upgrade your cabal-install to version 3.10.3 (recommended by GHCup), where this behavior was reversed (base is added by default).
To add to how brittle `install --lib` is: the 3.10.1 behavior (no base by default) bothered people [1] and was changed in 3.10.3 [2]. But the 3.10.3 behavior (add base by default) also bothers people [3]!
And note that although you have an easy way to solve your issue (add base in the list of libraries in the call to install --lib), the users of 3.10.3 who don't want base added by default don't have such an easy way.
(By easy I mean using only cabal CLI and don't edit env files manually, for example.)
More general, I think, it's possible to develop a mental model for today's `install --lib` (either 3.10.1 or 3.10.3, doesn't matter in the grand scheme),
and use it effectively for "little experiments" as advocated by Richard in the above-mentioned issue [4] (note that the issue was solved since!).
The prerequisite for that is to understand GHC environment files and that `install --lib` is mostly a (n incomplete) CLI interface to them.
Yet, people argue for a more holistic "environment" experience, see, e.g., the above mentioned [5] (the cabal-env issue)
or this thread :-)
Also, (much in the spirit of Carthago delenda est) I try to conclude my every reply about install --lib with what's already mentioned by Tom:
always use `cabal install --lib` with `--package-env=.` It will save you a bunch of pain related to the "global state" (not all of it, perhaps).
--
Best, Artem