在MINGW64中使用LAPACK

时间:2017-05-03 17:17:24

标签: gfortran lapack mingw-w64

我正在尝试将LAPACK合并到我正在尝试编译的程序中。我目前正在使用msys2工具链和MINGW64 gfortran编译器。我使用以下过程来获取LAPACK:

To get BLAS and LAPACK together
In Msys2 64 bit environment type in:
Pacman –S mingw-w64-x86_64-cmake #gets cmake
Pacman –S git #gets git
Git clone https://github.com/msys2/MINGW-packages.git
Cd MINGW-packages/mingw-w64-lapack

Then navigate to ~/MINGW-packages/mingw-w64-lapack and open the file called PKGBUILD.  Do a find and replace all from ‘RESPOSE’ to ‘RESPONSE’.  Save the file and exit the text editor. 

In the msys environment, type:
Makepkg-mingw
Pacman –U mingw-w64-x86_64-lapack*.pkg.tar.gz

BLAS and LAPACK are now installed.

To test lapack, do the following. 

> cd ~
> wget http://www.math.ucla.edu/~wotaoyin/software/lapack_test.cpp  # download
> g++ lapack_test.cpp -llapack -o lapack_test     # build
> ./lapack_test                                   # run

然后我尝试使用LAPACK编译程序。我的程序只调用sgetrf和sgetrs。但是,当我编译时,我收到以下错误:

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrf.f.obj):(.text+0x43a): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrf.f.obj):(.text+0x524): undefined reference to `sgemm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x159): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x1c5): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x340): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetrs.f.obj):(.text+0x3ac): undefined reference to `strsm_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x1c3): undefined reference to `isamax_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x212): undefined reference to `sswap_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x36c): undefined reference to `sger_'
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/6.2.0/../../../../lib\liblap
ack.a(sgetf2.f.obj):(.text+0x3ca): undefined reference to `sscal_'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [Makefile.all:20: avl] Error 1

链接liblapack.a时我缺少什么?

我的命令是:

gfortran -m64   -o avl  avl.o aoper.o amode.o amass.o asetup.o amake.o ainput.o
aoutput.o aero.o atrim.o atpforc.o aic.o cdcl.o airutil.o autil.o aplotvl.o aplo
ttp.o aplotmd.o limits.o pltops.o hidden.o plsubs.o userio.o plutil.o arrow3d.o
getvm.o matrix.o spline.o sgutil.o second.o -static  ../plotlib/libPlt_mingwSP.a
 ../eispack/libeispack.a -lgdi32 -luser32 -lblas -llapack

2 个答案:

答案 0 :(得分:0)

我想回答我自己的问题,因为我相信我发现了错误。

首先,看起来这些调用与BLAS有关。所以我需要添加-lblas来编译调用。但是,我最初尝试这个没有效果,然后在-llapack调用之后调用-lblas并且它起作用。

答案 1 :(得分:0)

这是另一种解决方案。从https://www.gnu.org/software/gcc/testing/testing-lapack.html获取代码。通过单击链接lapack.tgz下载。 make.inc文件已经设置好(您可能需要重命名),因此您所要做的就是运行make

在到达这一点之前,我走了好几条小巷。我以Google顺序尝试了它们。

  1. http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries给了我四个与gfortran不兼容的文件。也许我错读了该网页,但是无论如何,如果有兼容的库,我找不到它们。
  2. https://packages.msys2.org/package/mingw-w64-x86_64-lapack-下载并解压缩tar文件会得到与gfortran不兼容的文件。
  3. http://www.netlib.org/lapack/-下载并解压缩lapack-3.9.0.tar.gz。设计用于各种系统,但不包括mingw gfortran。生成文件和其他脚本比我想解决的要复杂。 https://gcc.gnu.org/wiki/LAPACK%20on%20Windows给出了一种解决方案,但已有8年的历史,必须对其进行更新。

您知道,难怪每个人都放弃使用这些标准库时会遇到这种困难。 Python,Matlab或Octave中内置了相同的东西