Linking Lapack with clapack to c++
Hello,
I have a sample c++ code I would like it working. Here it is:
I use the following command in order to compile:
However, I have the following compilation error:
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
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