Linking Lapack with clapack to c++

Open discussion regarding features, bugs, issues, vendors, etc.

Linking Lapack with clapack to c++

Postby ben-martin » Mon Jan 27, 2014 1:08 pm


I have a sample c++ code I would like it working. Here it is:

Code: Select all
extern "C"
   #include <f2c.h>
   #include <clapack.h>
#include <vector>
#include <iostream>
using namespace std;

int main()
   vector<double> mat(9);

   /// Stored columnwise
   mat[0] = 1.0; mat[1] = 2.0; mat[2] = 3.0;
   mat[3] = 2.0; mat[4] = 1.0; mat[5] = 3.0;
   mat[6] = 3.0; mat[7] = 1.0; mat[8] = 2.0;

   integer info = 10, dim = 3;
   vector<integer> pivotArray(dim);
  dgetrf_(&dim,              // number of rows
          &dim,              // number of columns
          &(mat[0]),  // array of coefficients
          &dim,              // number of columns inverted
          &(pivotArray[0]),  // array of pivot indices
          &info);            // result: 0 if success
   for(integer i = 0; i < dim; ++i)
      cout << pivotArray[i] << " ";
   cout << endl;

   return 0;

I use the following command in order to compile:
Code: Select all
g++ -llapack test.cpp

However, I have the following compilation error:
Code: Select all
/tmp/ccflNmTs.o: In function `main':
test.cpp:(.text+0x1de): undefined reference to `dgetrf_'
collect2: ld returned 1 exit status

Note that I manage to use dgetrf_ from a library that I compiled without any issue (and the code is working from this library). I take a look at the flags used to compile this library, which are "-llapack -llblas -lf2c". I used this command, but the same error appears. I also tried to give the absolute path to the lapack library, and it is still not working. I found some related topic on the net, but issues where only on the use of " extern "C" ", which seems to be correct in my case. Note finally the signature of "dgetrf_" is defined in "clapack.h".

I work on Ubuntu 12.04 64 bit. The lapack version is 3.3.1
Posts: 1
Joined: Mon Jan 27, 2014 12:32 pm

Return to User Discussion

Who is online

Users browsing this forum: No registered users and 1 guest