Thursday, July 16, 2009

Compile LAPACK and BLAS as DLL on Windows

BLAS (Basic Linear Algebra Subprograms) is a library that provides standard routines for basic vector and matrix operations.


LAPACK is a library that provides functions for solving systems of linear equations, matrix factorizations, solving eigenvalue and singular value problems. LAPACK library have dependency to BLAS library because of the LAPACK functions using BLAS functions to work.


Both of those libraries are written in Fortran77 and no binaries provided for windows. The sources are downloadable from netlib site. So you can compile and use their libraries. However makefile and make solutions for compiling under windows are cumbersome.


So I recommend compiling directly from the sources using a FORTRAN compiler. There is a free and open source FORTRAN compiler for Windows which is the port of gnu FORTRAN compiler for Windows. You could also use Cygwin and tools in cygwin but your dynamic library loader will have dependency to cygwin dlls. MinGW is a collection of tools that allows you to produce native Windows programs. G77, make, gcc are the common tools provided by Mingw.


Here are the steps to go to compilation



  • Download most current version of LAPACK from Netlib and extract the sources

  • Download almost all of the Mingw tools and extract the tools

  • Copy dlamch.f and slamch.f from INSTALL directory SRC directory


  • Set path to have mingw binaries


    • set PATH=c:\mingw\bin\;%PATH%



  • Go to root directory of the extracted folder and compile using g77


  • First compile BLAS. –shared option is needed in order to functions to be exposed from the dll. -O generates optimised code. -o filename is the output file


    • g77 –shared -o blas.dll BLAS\SRC\*.f –O




  • Compile LAPACK with BLAS dependency


    • g77 –shared -o lapack.dll src\*.f blas.dll -O




Here is the output:



c:\\lapack-3.1.1\\copy INSTALL\\dlamch.f SRC\\dlamch.f
1 file(s) copied.
c:\\lapack-3.1.1\\copy INSTALL\\slamch.f SRC\\slamch.f
1 file(s) copied.
c:\\lapack-3.1.1\\set PATH=c:\\tools\\mingw\\bin\\;%PATH%

c:\\lapack-3.1.1\\g77 --shared -o blas.dll BLAS\\SRC\\*.f -O

c:\\lapack-3.1.1\\g77 --shared -o lapack.dll src\\*.f blas.dll -O

Hope this helps.

1 comment:

Anonymous said...

Can you please give a reference where you steeled this information from? Are all your posts someone else's posts?
http://www.canerten.com/compile-lapack-and-blas-as-dll-on-windows/