zeus300
zeus300

Reputation: 1075

Can't get LAPACK to run on windows

I am trying to get LAPACK to run on windows. I downloaded version 3.8.0 from netlib.org and built the libraries using CMAKE.

I don't have a MSVC license, so I'm using mingw64. Here's my code:

#include "lapacke.h"
#include <iostream>

extern "C" {
   extern int LAPACKE_zgesv(int matrix_order, lapack_int n, lapack_int nrhs,
                          lapack_complex_double* a, lapack_int lda,
                          lapack_int* ipiv, lapack_complex_double* b,
                          lapack_int ldb );
    }

using namespace std;

int main (int argc, char* argv[])
{
   cout << "Hello 1" << endl;

   /* Locals */
   lapack_int n = 4, nrhs = 2, lda = 4, ldb = 2, info;
   /* Local arrays */
   lapack_int ipiv[4];
   lapack_complex_double a[4*4] = {
      { 1.23, -5.50}, { 7.91, -5.38}, {-9.80, -4.86}, {-7.32,  7.57},
      {-2.14, -1.12}, {-9.92, -0.79}, {-9.18, -1.12}, { 1.37,  0.43},
      {-4.30, -7.10}, {-6.47,  2.52}, {-6.51, -2.67}, {-5.86,  7.38},
      { 1.27,  7.29}, { 8.90,  6.92}, {-8.82,  1.25}, { 5.41,  5.37}
   };
   lapack_complex_double b[2*4] = {
      { 8.33, -7.32}, {-6.11, -3.81},
      {-6.18, -4.80}, { 0.14, -7.71},
      {-5.71, -2.80}, { 1.41,  3.40},
      {-1.60,  3.08}, { 8.54, -4.05}
   };     

   info = LAPACKE_zgesv( LAPACK_ROW_MAJOR, n, nrhs, a, lda, ipiv, b, ldb );

   cout << "Hello 2" << endl;
}

I compile like this:

g++ minimal.cpp -I./Include -LLib -llapacke -o minimal.exe

The compiler runs through without errors, but when I run the executable, I get no output. The couts at the beginning and at the end of the program are not executed. When I comment out the line with the LAPACKE_zgesv function, I do get output from the couts.

So I am not sure what is happening. It seems like the program notices that for some reason it cannot find the LAPACK function and just quits, but without complaining.

Upvotes: 0

Views: 480

Answers (2)

zeus300
zeus300

Reputation: 1075

Ok, I know what the problem is. I need to put the libblas.dll, liblapack.dll and liblapacke.dll in the directory where the .exe resides. I only found out because I tried the black cmd shell for a change, and that talked to me. The damn Powershell thought it wasn't necessary to say anything about the missing dlls. Man!

I also have to put libstdc++-6.dll, libgcc_s_seh-1.dll, libgfortran-5.dll, libquadmath-0.dll, and libwinpthread-1.dll in that directory. By adding -static-libstdc++ and -static-libgcc I can link the first two statically. Are there equivalent static directives for the other three? Also, I do have the static lapack libs. What linker commands would I have to specify for linking those so that everything is static? If I add a simple -static, the linker complains that it can't find -llapacke, although it is there.

Upvotes: 0

Brecht Sanders
Brecht Sanders

Reputation: 7287

Try version 3.9.0 from https://github.com/Reference-LAPACK/lapack/releases

For me this builds fine with MinGW-w64, though I had to run these commands before running cmake to fix the issue mentioned in https://github.com/Reference-LAPACK/lapack/pull/370:

patch -ulbf LAPACKE/src/lapacke_cgesvdq.c << EOF
@@ -72,4 +72,4 @@
     }
-    liwork = (lapack_int)iwork_query;
-    lcwork = (lapack_int)cwork_query;
+    liwork = iwork_query;
+    lcwork = LAPACK_C2INT(cwork_query);
     lrwork = (lapack_int)rwork_query;
EOF
patch -ulbf LAPACKE/src/lapacke_zgesvdq.c << EOF
@@ -72,4 +72,4 @@
     }
-    liwork = (lapack_int)iwork_query;
-    lcwork = (lapack_int)cwork_query;
+    liwork = iwork_query;
+    lcwork = LAPACK_C2INT(cwork_query);
     lrwork = (lapack_int)rwork_query;
EOF

I use the following CMake flags: -DBUILD_SINGLE:BOOL=ON -DBUILD_DOUBLE:BOOL=ON -DBUILD_COMPLEX:BOOL=ON -DBUILD_COMPLEX16:BOOL=ON -DCBLAS:BOOL=ON -DBLAS++:BOOL=OFF -DLAPACKE:BOOL=ON -DLAPACKE_BUILD_COMPLEX:BOOL=ON -DLAPACKE_BUILD_COMPLEX16:BOOL=ON -DLAPACKE_BUILD_DOUBLE:BOOL=ON -DLAPACKE_BUILD_SINGLE:BOOL=ON -DLAPACK++:BOOL=OFF -DLAPACKE_WITH_TMG:BOOL=ON -DBUILD_DEPRECATED:BOOL=OFF -DBUILD_TESTING:BOOL=OFF and, depending on wether you want a static or shared build, -DBUILD_SHARED_LIBS:BOOL=OFF or -DBUILD_SHARED_LIBS:BOOL=ON

When I run your example I get the output:

Hello 1
Hello 2

Upvotes: 1

Related Questions