[英]How to work together with cabal-3 and ghc (ghc-pkg, too)?
随着 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.
此错误在此处描述
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)
via 在 Windows 上,用 cabal 安装的包在 ghc/ghci 中似乎不可用
但是随着更新,我将不得不手动更改这个系统变量。
这个问题有没有更优雅的解决方案?
PS 不幸的是,这个解决方案(通过 GHC 的环境变量 GHC_PACKAGE_PATH)与 Cabal 不兼容:(
实现此目的的一种方法是使用--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
文件的目录中执行此操作。 有关详细信息,请参阅cabal v2-install
的文档。
使用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,步骤类似。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.