随着cabal-3的发布,来自Hackage的包被安装在编译器ghc和ghc-pkg一无所知的新位置。换句话说,安装了软件包,但没有为ghc注册。Ghci、ghc和ghc-pkg无法工作。
例如,
cabal install safe --lib创建文件t1.hs
import Safe
t1 = tailMay [1,2,3]让我们试一试:
> ghci t1.hs
GHCi, version 8.10.2: https://www.haskell.org/ghc/:? for help
[1 of 1] Compiling Main (t1.hs, interpreted)
t1.hs: 1: 1: error:
Could not find module `Safe '
Use -v (or `: set -v` in ghci) to see a list of the files searched for.
|
1 | import Safe
| ^^^^^^^^^^^
Failed, no modules loaded.这里描述了这个bug
https://github.com/haskell/cabal/issues/6262
还有这里
https://gitlab.haskell.org/ghc/ghc/-/issues/17341
我使用设置系统变量作为临时解决方案
GHC_PACKAGE_PATH=C:\Users\me\AppData\Roaming\cabal\store\ghc-8.10.2\package.db;(Windwos 10,haskell-dev by chocolatey)
通过On Windows, packages installed with cabal seem to be unavailable in ghc/ghci
但在更新时,我必须手动更改此系统变量。
对于这个问题,有没有更好的解决方案?
注:不幸的是,这个解决方案(通过GHC的环境变量GHC_PACKAGE_PATH)与Cabal不兼容:(
发布于 2020-08-30 21:29:37
要实现这一点,一种方法是在当前目录中使用--env标志使这些库可供GHC使用:
~ $ mkdir /tmp/foo
~ $ cd /tmp/foo
/tmp/foo $ cabal install safe --lib --env .
Resolving dependencies...
Build profile: -w ghc-8.8.3 -O1
In order, the following will be built (use -v for more details):
- safe-0.3.19 (lib) (requires build)
Configuring library for safe-0.3.19..
Preprocessing library for safe-0.3.19..
Building library for safe-0.3.19..
…
> Installing library in /home/jojo/.cabal/store/ghc-8.8.3/incoming/new-4056/home/jojo/.cabal/store/ghc-8.8.3/safe-0.3.19-92fbaef88124b4508ce447f6245bc793f7a1748247ae68d10e449150df1069af/lib
t1.hs
/tmp/foo $ cat > t1.hs
import Safe
t1 = tailMay [1,2,3]
/tmp/foo $ ls -a
. .. .ghc.environment.x86_64-linux-8.8.3 t1.hs
/tmp/foo $ ghci t1.hs
GHCi, version 8.8.3: https://www.haskell.org/ghc/ :? for help
Loaded package environment from /tmp/foo/.ghc.environment.x86_64-linux-8.8.3
[1 of 1] Compiling Main ( t1.hs, interpreted )
Ok, one module loaded.
*Main> 请注意,您可能不应该在实际具有foo.cabal文件的目录中执行此操作。详情请参见the documentation of cabal v2-install。
发布于 2020-09-12 01:51:53
使用GHC_ENVIRONMENT更好:
setx GHC_ENVIRONMENT C:\Users\me\.ghc\x86_64-mingw32-8.10.2\environments\default它对ghc和ghci很有帮助。
之后,在C:\Users\me\AppData\Roaming\cabal\config中,我们应该添加
package-db: C:\Users\me\AppData\Roaming\cabal\store\ghc-8.10.2\package.db这对cabal很有帮助。
不幸的是,ghc-pkg仍然有问题,并且使用这样的标志:
ghc-pkg list --user-package-db="C:\Users\me\AppData\Roaming\cabal\store\ghc-8.10.2\package.db"对于Linux,这些步骤是相似的。
https://stackoverflow.com/questions/63654347
复制相似问题