1

使用 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 cabalhmatrixMain构建简单的测试项目

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。我在目录中看到 hmatrix "C:\cabal\store\ghc-8.10.7\hmatrix-0.20.2-e917eca0fc7690010007a19f4f2a3602d86df0f0"


创建的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 项目后,它正在工作。

4

1 回答 1

2

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

但是你怎么能传递必要的标志呢?cabal.project文件

packages: .

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

将此文件与cabalhmatrix.cabal. 然后cabal build在该目录中运行将使用hmatrix带有合适库等标志的安装。

于 2021-09-07T15:49:36.217 回答