# Gfortran compiled LAPACK libraries for Windows

**URL:** <https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444>\
**Category:** Uncategorized\
**Created:** [November 26, 2020, 4:44am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444 "2020-11-26T04:44:05Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [November 26, 2020, 4:44am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/1 "2020-11-26T04:44:05Z")

</div>

Using [these instructions](https://gcc.gnu.org/wiki/LAPACK%20on%20Windows), I was able to compile LAPACK 3.4.0 using gfortran on Windows, after adding the option -std=legacy to the files make.inc and make.inc.example. The three library files created can be downloaded [here](https://1drv.ms/u/s!Aigf3ob4jrIJhPwTb6DGkRw813iJuQ?e=VG1lZD).

The same instructions do not work for LAPACK 3.9.0. Does anyone know how they should modified, or can anyone make available Windows gfortran library files for LAPACK 3.9.0?

---

<div class="post-metadata">

**Author:** ![lkedward](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/lkedward/32/72_2.png) [@lkedward](https://fortran-lang.discourse.group/u/lkedward)\
**Post date:** [November 26, 2020, 3:00pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/2 "2020-11-26T15:00:32Z")

</div>

I’ve been meaning to test out an MSYS2 workflow in github actions for some time, so I’ve put together a simple [repository](https://github.com/LKedward/lapack-build) compiling LAPACK 3.9.0 using the MSYS2 build of mingw-w64 and cmake.

You can download the resulting library files [here](https://github.com/LKedward/lapack-build/releases) and view the [build script](https://github.com/LKedward/lapack-build/blob/main/.github/workflows/build_deploy.yml) and workflow [output](https://github.com/LKedward/lapack-build/runs/1459115292?check_suite_focus=true) as well.

I’ve run a minimal test on the libraries locally but all LAPACK test cases run and pass in the CI workflow.  
Hope this helps; do let me know if you run into any problems with it.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [March 23, 2021, 10:21pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/3 "2021-03-23T22:21:53Z")

</div>

I was able to compile

- [BLAS and LAPACK 3.9.0](https://masuday.github.io/fortran_tutorial/external.html#blas-and-lapack)
- [LAPACK95](https://masuday.github.io/fortran_tutorial/external.html#lapack95)
- [RANLIB](https://masuday.github.io/fortran_tutorial/external.html#ranlib)
- [CDFLIB](https://masuday.github.io/fortran_tutorial/external.html#cdflib)

using the [equation.com](http://equation.com) gfortran compiler on Windows, using the [instructions](https://masuday.github.io/fortran_tutorial/external.html) of Yutaka Masuda . I [uploaded](https://github.com/Beliavsky/gfortran_windows_compiled_libs) the library files to GitHub.

---

<div class="post-metadata">

**Author:** ![Ashok](https://avatars.discourse-cdn.com/v4/letter/a/ed655f/32.png) [@Ashok](https://fortran-lang.discourse.group/u/Ashok)\
**Post date:** [August 6, 2021, 12:13pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/4 "2021-08-06T12:13:16Z")

</div>

Can we use these files under Visual studio ?  
What is the procedure ?

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 7, 2021, 10:39pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/5 "2021-11-07T22:39:10Z")

</div>

You said “Gfortran compiled LAPACK libraries for Windows” in the topic. Then, the mentioned files and instructions produce “.a” library that is suitable for the Linux environment. They even don’t produce a static library.  
Of course, if I understand it correctly.

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [November 7, 2021, 11:22pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/6 "2021-11-07T23:22:49Z")

</div>

The .a files work on Windows for me. Using CMD,

```auto
git clone https://github.com/Beliavsky/gfortran_windows_compiled_libs.git
cd gfortran_windows_compiled_libs
cmpl.bat

```

produces two executables – the drivers are [here](https://github.com/Beliavsky/gfortran_windows_compiled_libs).

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 8, 2021, 6:26am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/7 "2021-11-08T06:26:52Z")

</div>

I seek to way build a new version of LAPACK to produce “.lib” file on Windows. I do some work on it but I face a weird problem in linking. I use the [first](https://masuday.github.io/fortran_tutorial/lib/test_blas.f90) program. Then, by the following commands, I want to link it to library:

> gfortran -c test\_blas.f95  
> gfortran -o main.exe test\_blas.o -L(path to library)\libblas.lib

The compiler showed:

> test\_blas.o:test\_blas.f95:\<.txt0x4\>: undefined reference to ‘dgemm\_\_’  
> collect2.exe: error: ld returened 1 exit status

So, I decided to use “librefblas.lib” and again it showed the above error. I repeated this procedure for “librefblas.a” and even download your files and repeated but it still showed the above error.

Can you help to find which step is wrong?

---

<div class="post-metadata">

**Author:** ![Euler-37](https://avatars.discourse-cdn.com/v4/letter/e/b19c9b/32.png) [@Euler-37](https://fortran-lang.discourse.group/u/Euler-37)\
**Post date:** [November 8, 2021, 9:22am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/8 "2021-11-08T09:22:15Z")

</div>

The package `openblas` is good for windows. if Using msys2(gfortran), `pacman -S "openblas package name"`. If Using MingW, besides compiled it yourself, the easy way is download the binary release [openblas](https://github.com/xianyi/OpenBLAS/releases),just copy the directory at “MinGW path”.

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 8, 2021, 10:29am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/9 "2021-11-08T10:29:13Z")

</div>

> [@VOLCANIC\_9](#):
>
> Can you help to find which step is wrong?

You are not issuing a correct linking command. Specifically, you are misusing the **-L** option, which is intended only to specify directories **where** libraries are located (in addition to default library directories). The **-L** option does not specify **which** libraries are to be linked – the option for that is the **-l** option. If you have BLAS and Lapack libraries installed in their default locations, the command to use is

```auto
gfortran test_blas.f95 -lblas -o main.exe

```

Because you used a faulty linking command, no libraries were used in addition to the default libraries used with any Fortran program.

Furthermore, if no BLAS library is used, rebuilding or switching to a different version of the (unused) BLAS or Lapack libraries will, obviously, have no effect on the result of the (faulty) linking command.

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 8, 2021, 6:21pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/10 "2021-11-08T18:21:54Z")

</div>

OK, good hint. The issue was solved for [first](https://masuday.github.io/fortran_tutorial/lib/test_blas.f90) test. However; the [second](https://masuday.github.io/fortran_tutorial/lib/test_lapack.f90) test is a new issue. This time I wrote command as:

> gfortran -o main.exe test\_lapack.f95 -L(path to the first library) -l(first library’s name) -L(path to the second library) -l(second library’s name)

This time the error was too long. For being reproducible, the first library is liblapack.dll and the second is libblas.dll.

Also, I tried it with just libblas, it showed:

> test\_blas.o:test\_blas.f95:\<.txt0x4\>: undefined reference to ‘dposv\_’  
> collect2.exe: error: ld returened 1 exit status

I am really confused.

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 8, 2021, 6:41pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/11 "2021-11-08T18:41:00Z")

</div>

Instead of presenting your paraphrase of the command that failed, please show the command _exactly as you entered it_.

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 8, 2021, 6:55pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/12 "2021-11-08T18:55:39Z")

</div>

For using liblapack.dll and libblas.dll, I wrote:

> gfortran -o main.exe test\_lapack.f95 -LG:\Myproject\LAPACKtest -lliblapack -LG:\Myproject\LAPACKtest -llibblas

For using libblas.dll, I wrote:

> gfortran -o main.exe test\_lapack.f95 -LG:\Myproject\LAPACKtest -llibblas

---

<div class="post-metadata">

**Author:** ![wclodius](https://avatars.discourse-cdn.com/v4/letter/w/87869e/32.png) [@wclodius](https://fortran-lang.discourse.group/u/wclodius)\
**Post date:** [November 8, 2021, 8:44pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/13 "2021-11-08T20:44:32Z")

</div>

In specifying a specific library the lib prefix should be omitted. Try

```auto
    gfortran -o main.exe test_lapack.f95 -LG:\Myproject\LAPACKtest -llapack - LG:\Myproject\LAPACKtest -blas

```

and

```auto
gfortran -o main.exe test_lapack.f95 -LG:\Myproject\LAPACKtest -lblas

```

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 9, 2021, 7:01am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/14 "2021-11-09T07:01:23Z")

</div>

First, it was strange that gfortran found libraries.  
Second, it did not work.  
I think the problem is not about finding libraries. It is about built libraries. Also, I don’t know how the “.a” file runs in Windows. It seems an interface app is needed.

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 9, 2021, 7:13am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/15 "2021-11-09T07:13:19Z")

</div>

```auto
gfortran test_lapack.f95 -LG:\Myproject\testlapack -llapack -lblas -o main.exe

```

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 9, 2021, 7:29am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/16 "2021-11-09T07:29:47Z")

</div>

This is what it showed:

> G:\Myproject\testlapack\>gfortran test\_lapack.f95 -LG:\Myproject\testlapack -llapack -LG:\Myproject\testlapack -lblas -o main.exe  
> g:/program file/gcc/gcc/bin/…/lib/gcc/x86\_64-w64-mingw32/9.2.0/…/…/…/…/lib/  
> libgfortran.a(transfer.o): In function `_gfortran_transfer_real_write': /home/gfortran/gcc-home/workshop/gcc/objdir64/x86_64-w64-mingw32/libgfortran/../ ../../gcc-9.2.0-mingw/libgfortran/io/transfer.c:2401: multiple definition of `\_g  
> fortran\_transfer\_real\_write’  
> G:\Myproject\testlapack/liblapack.dll(d000076.o):(.text+0x0): first defined here  
> g:/program file/gcc/gcc/bin/…/lib/gcc/x86\_64-w64-mingw32/9.2.0/…/…/…/…/lib/  
> libgfortran.a(compile\_options.o): In function `_gfortran_set_options': /home/gfortran/gcc-home/workshop/gcc/objdir64/x86_64-w64-mingw32/libgfortran/../ ../../gcc-9.2.0-mingw/libgfortran/runtime/compile_options.c:147: multiple defini tion of `\_gfortran\_set\_options’  
> G:\Myproject\testlapack/liblapack.dll(d000041.o):(.text+0x0): first defined here  
> g:/program file/gcc/gcc/bin/…/lib/gcc/x86\_64-w64-mingw32/9.2.0/…/…/…/…/lib/  
> libgfortran.a(main.o): In function `_gfortran_set_args': /home/gfortran/gcc-home/workshop/gcc/objdir64/x86_64-w64-mingw32/libgfortran/../ ../../gcc-9.2.0-mingw/libgfortran/runtime/main.c:46: multiple definition of `\_gf  
> ortran\_set\_args’  
> G:\Myproject\testlapack/liblapack.dll(d000037.o):(.text+0x0): first defined here  
> collect2.exe: error: ld returned 1 exit status

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 9, 2021, 8:23am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/17 "2021-11-09T08:23:41Z")

</div>

The error messages indicate that now you are using DLL versions of Lapack and BLAS, which may not be compatible with the version of Gfortran that you are using. Where did those DLLs come from?

In your previous posts, you only mentioned static libraries (libblas.a, liblapack.a).

Mixing of libraries built with different versions of Gfortran (or different GCC distributions for Windows) is quite likely to cause linking problems.

---

<div class="post-metadata">

**Author:** ![VOLCANIC\_9](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/volcanic_9/32/1047_2.png) [@VOLCANIC\_9](https://fortran-lang.discourse.group/u/VOLCANIC_9)\
**Post date:** [November 9, 2021, 9:02am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/18 "2021-11-09T09:02:50Z")

</div>

Dear @mecej4;  
First, I mentioned “libblas.a” and “liblapack.a” cause @Beliavsky said they worked in her/his Windows platform. Otherwise, these files are not even static or even dynamic libraries on the Windows platform. Moreover, employing them resulted in:

> file not recognized: File format not recognized  
> collect2.exe: error: ld returned 1 exit status

Second, It is not important for LAPACK that contribute to compiling level or linking level. You could use them as “.lib” file in compiling level or “.dll” file in linking level. Furthermore, I tried both approaches and both lead to the same error as mentioned above.

Third, I built LAPACK files both with the same Gcc and Make.

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 9, 2021, 11:14am UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/19 "2021-11-09T11:14:02Z")

</div>

@Volcanic_9, let me try a different approach to making this work.

I have a Windows 10 64-bit PC with a 10th generation Intel CPU. I have Gfortran 11.2 installed as part of Cygwin-64. Note that I am not using any 32-bit object files, libraries, DLLs or EXEs in the present context.

I created a fresh directory, and downloaded Beliavsky’s libreblas.a and liblapack.a into that directory, from the links that he gave in #6 above. Both those are standard Unix/Linux/Cygwin archives, containing Intel amd64 COFF object files. Note that he built the libraries using the Equation\_dot\_com distribution of Gfortran (64-bit). I compiled the two test examples and linked them to the downloaded libraries:

```auto
T:\Beliavsky>gfortran test_blas.f90 -L. -lrefblas

T:\Beliavsky>file a.exe
a.exe: PE32+ executable (console) x86-64, for MS Windows

T:\Beliavsky>gfortran test_lapack.f90 -L. -llapack -lrefblas

```

The resulting EXEs run fine and give the expected results. Using the same Cygwin 64-bit Gfortran 11.2, I used the Cygwin-64 versions of the Lapack and BLAS libraries. Worked fine. I then built EXEs using Gfortran with the Intel OneAPI DLL mkl\_rt.dll (64-bit).

```auto
gfortran test_lapack.f90 c:\LANG\PS20\compilers_and_libraries_2020.4.311\windows\redist\intel64\mkl\mkl_rt.dll

```

and similarly for test\_blas.f90. Again, the resulting EXEs ran fine.

---

<div class="post-metadata">

**Author:** ![mecej4](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/mecej4/32/855_2.png) [@mecej4](https://fortran-lang.discourse.group/u/mecej4)\
**Post date:** [November 9, 2021, 3:55pm UTC](https://fortran-lang.discourse.group/t/gfortran-compiled-lapack-libraries-for-windows/444/20 "2021-11-09T15:55:30Z")

</div>

> [@VOLCANIC\_9](#):
>
> Second, It is not important for LAPACK that contribute to compiling level or linking level. You could use them as “.lib” file in compiling level or “.dll” file in linking level.

That is incorrect. The compiler never uses any libraries, static or dynamic, with suffixes **.a** , **.lib** or . **dll** , when it is compiling a Fortran source file into an object file, which will have suffix **.o** or **.obj**. If you have specified the **-c** option, the compiler stops after producing module and object files, so any libraries specified with **-L** and **-l** options will be ignored.
