LAPACK on Windows with Visual Studio 2010

Posted On February 11, 2011

Filed under Code+Math, CS

Comments Dropped 2 responses

Scenario: you are pulling your hair out and are about to start punching your monitor (don’t! you’ll regret it) because you found this website:
http://icl.cs.utk.edu/lapack-for-windows/lapack/,
you followed all the steps, and you are still getting love letters from your compiler / linker saying “error LNK2001 unresolved external symbol” (or something equally frustrating).

Solution: If you are not going to be solving huge matrix systems, you do not care about performance, and pre-compiled Windows versions BLAS and Lapack are sufficient for you, read on.

If you happened to follow the instructions in that Lapack link above, and managed to trick Win7 into letting you paste BLAS.lib in the Windows/System32 directory, go ahead and delete it (you don’t want junk floating around, do you?). Also, delete all the stuff you downloaded from the website. Delete the project you were trying to compile too! Start over!

  1. Download the most recent stable version of Armadillo
  2. Create an empty C++ solution in VS 2010.
  3. Create a source code file, paste the tutorial code
  4. Add extern “C” in front of the function prototypes: void dgesv_( ) —– >    extern “C” void dgesv_( )
  5. In project properties, go to Configuration Properties -> Linker -> Input
    In Additional Dependencies add lapack_win32_MT.lib;blas_win32_MT.lib;
  6. Untar your Armadillo download. Go to armadillo-1.0.2\examples\lib_win32
  7. From lib_win32 copy lapack_win32_MT.lib and .dll and blas_win32_MT.lib and .dll and paste them in the same project directory where your source (.cpp) file is.
  8. Compile, Run… (the solution is -0.661082, 9.456125, -16.014625).

Taa-dah!

Several notes:

  1. If you want to put your libraries in a separate directory and set the linker directories, go ahead. This is obviously the most basic setup.
  2. This should work with VS 2008 and Windows XP and later (32-bit). You might have problems with the pre-compiled libraries. If you happen to encounter problems and still do not want to make your own compiles of Lapack and BLAS, Armadillo website provides additional sources for the pre-compiled versions of Lapack and BLAS at the bottom of this page.

2 Responses to “LAPACK on Windows with Visual Studio 2010”

  1. David

    That really worked for me . thanks a lot.

  2. Andy

    That helped me a ton too, I was have issues with linking and the unresolved external variable. You seriously made my day

Leave a comment