2

I am trying to incorporate LAPACK into a program I am trying to compile. I am currently using the msys2 toolchain with the MINGW64 gfortran compiler. I used the following process to obtain 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

I then attempt to compile the program using LAPACK. My program only calls sgetrf and sgetrs. However, when I compile I receive the following errors:

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

What am I missing in linking liblapack.a?

My command is:

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
user3883001
  • 99
  • 3
  • 7

2 Answers2

0

I wanted to answer my own question as I believe I found the error.

First, it looks like these calls are related to BLAS. So I needed to add -lblas to compile call. However, I initially tried this to no effect and then called -lblas AFTER the -llapack call and it worked.

user3883001
  • 99
  • 3
  • 7
  • See [Why does the order in which libraries are linked sometimes cause errors in GCC?](http://stackoverflow.com/q/45135/1362568) – Mike Kinghan May 04 '17 at 12:55
  • I wish I new why the order matters. I want to add some comments to help others who, like me, are not up on all the idiosyncrasies of gnu. I had a heck of a time figuring out how to link these libraries First, to link with liblapack.a I tried -l liblapack. No, you must use -l lapack. The second issue is the libraries must be specfied at the end of the command line. And third, they must be linked in the order shown. This took quite sometime to figure out. The order of options matters only in the gnu world. I'm sure this is explained someplace, but it is not intuitive. – L. Young Jun 20 '20 at 17:49
0

Here is another solution. Get the code from https://www.gnu.org/software/gcc/testing/testing-lapack.html. Download by clicking on the link lapack.tgz. The make.inc file is already setup (you may have to rename it), so all you have to do is run make.

I went down several blind alleys before getting to this point. I tried them in google order.

  1. http://icl.cs.utk.edu/lapack-for-windows/lapack/#libraries gave me four files which are not compatible with gfortran. Maybe I missread the webpage, but at any rate, if the compatible libraries are there, I didn't find them.
  2. https://packages.msys2.org/package/mingw-w64-x86_64-lapack - downloading and unpacking the tar file gives files which don't work with gfortran.
  3. http://www.netlib.org/lapack/ - download and unpack lapack-3.9.0.tar.gz. This is designed to be made on a wide variety of systems, but doesn’t include mingw gfortran. The make files and other scripts are more complicated than I wanted to tackle. One solution is given at https://gcc.gnu.org/wiki/LAPACK%20on%20Windows, but it is 8 years old and would have to be updated.

You know, it is no wonder everyone has abandoned Fortran when it is this difficult do use these standard libraries. The same stuff is built into Python, Matlab or Octave

L. Young
  • 113
  • 9
  • 1
    "everyone has abandoned Fortran" that is new to me and to many other people on this [tag:fortran] tag. Lapack is extremely easy to install and comes pre-installed with most Linux distributions. It is the Windows ecosystem that is lacking. If the files in 1) are supposed to be incompatible with gfortran, you have to say in which way. Lapack does not use any special features that require array descriptors or modules. I have succesfully mixed MSVC compiled code with gfortran compiled libraries. You have to download the right version, not the Intel version. – Vladimir F Героям слава Jun 21 '20 at 11:21
  • 2. What is "don't work" supposed to mean? What do they work with then? 3. In which ways would the solution have to be updated? Lapack is older than that. What specifically is wrong? – Vladimir F Героям слава Jun 21 '20 at 11:25