如何在 Windows 10 下使用 hmatrix 正确构建 cabal 项目?

How to correctly build cabal project using hmatrix under Windows 10?

使用 Windows 10 64 位,Cabal-3.4.0.0,ghc-8.10.7。 我使用命令在 MSYS2 环境中安装了 OpenBLAS pacman -S mingw-w64-x86_64-openblas。 然后,我用命令

成功安装了hmatrix-0.20.2
cabal install --lib hmatrix --flags=openblas --extra-include-dirs="C:\ghcup\msys64\mingw64\include\OpenBLAS" --extra-lib-dirs="C:\ghcup\msys64\mingw64\bin" --extra-lib-dirs="C:\ghcup\msys64\mingw64\lib"

我正在尝试使用 cabal build cabalhmatrix 和 Main

构建简单的测试项目
module Main where

import Numeric.LinearAlgebra

main :: IO ()
main = do
  putStrLn $ show $ vector [1,2,3] * vector [3,0,-2]

但现在我得到了输出

Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- hmatrix-0.20.2 (lib) (requires build)
- cabalhmatrix-0.1.0.0 (exe:cabalhmatrix) (first run)
Starting     hmatrix-0.20.2 (lib)

Failed to build hmatrix-0.20.2. The failure occurred during the configure
step.
Build log (
C:\cabal\logs\ghc-8.10.7\hmatrix-0.20.2-6dd2e8f2795550e4dd624770ac98c326dacc0cac.log
):
Warning: hmatrix.cabal:21:28: Packages with 'cabal-version: 1.12' or later
should specify a specific version of the Cabal spec of the form
'cabal-version: x.y'. Use 'cabal-version: 1.18'.
Configuring library for hmatrix-0.20.2..
cabal-3.4.0.0.exe: Missing dependencies on foreign libraries:
* Missing (or bad) C libraries: blas, lapack
This problem can usually be solved by installing the system packages that
provide these libraries (you may need the "-dev" versions). If the libraries
are already installed but in a non-standard location then you can use the
flags --extra-include-dirs= and --extra-lib-dirs= to specify where they are.If
the library files do exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.

cabal-3.4.0.0.exe: Failed to build hmatrix-0.20.2 (which is required by
exe:cabalhmatrix from cabalhmatrix-0.1.0.0). See the build log above for
details.

我应该怎么做才能正确构建该包? 我想我需要在编译期间以某种方式将参数 --flags=openblas --extra-include-dirs="C:\ghcup\msys64\mingw64\include\OpenBLAS" --extra-lib-dirs="C:\ghcup\msys64\mingw64\bin" --extra-lib-dirs="C:\ghcup\msys64\mingw64\lib" 传递给 hmatrix,但不知道该怎么做。老实说,我不明白这些参数(cabal、ghc、ghc-pkg 或其他)究竟是为了什么程序,以及为什么 cabal 试图再次安装 hmatrix。我在目录 "C:\cabal\store\ghc-8.10.7\hmatrix-0.20.2-e917eca0fc7690010007a19f4f2a3602d86df0f0".

中看到 hmatrix

已创建 cabal.project 文件:

packages: .

package hmatrix
  flags: +openblas
  extra-include-dirs: C:\ghcup\msys64\mingw64\include\OpenBLAS
  extra-lib-dirs: C:\ghcup\msys64\mingw64\bin, C:\ghcup\msys64\mingw64\libenter code here

libopenblas.dll 位置添加到 PATH 变量 cabal 项目后正在运行。

即使有 --lib 标志,通常最好在 Cabal 不安装库 的假设下工作。永远不要安装库,而只是依赖它——并在必要时让 Cabal 安装、更新等。

但是你怎么能传递必要的标志呢? 有了cabal.project file.

packages: .

package hmatrix
   flags: openblas
   extra-include-dirs: C:\ghcup\msys64\mingw64\include\OpenBLAS
   ...

把这个文件和cabalhmatrix.cabal放在你自己项目的工作目录下。然后该目录中的 运行 cabal build 将使用带有合适库等标志的 hmatrix 安装。