Hi all,
I have used lapack in c++ on red hat previously and i had no problem to link the libraries with:
g++ test.C -L/usr/lib/ -llapack -lblas -lm -lg2c
Now I am working on my laptop which has Ubuntu with the lapack provided by Synaptic and the previous command didn't work anymore. It gave me:
/usr/bin/ld: cannot find -llapack
collect2: ld returned 1 exit status
So after a look to the usr/lib folder, i changed the command by:
g++ test.C -L/usr/lib/liblapack.so.3 -lblas -lm -lg2c
But now I have another error:
/tmp/ccfwmBwU.o: In function `main':
test.c.text+0x151): undefined reference to `dgesv_'
collect2: ld returned 1 exit status
It seems that I don't export the function correctly. Does anyone have any idea about this?
Thanks
Huy-Nam
ps: here is the code
#include <iostream>
#define MAX 10
extern "C" {
extern void dgesv_(int *,int *,double *,int *,int*,double *,int*,int*);
};
int main(){
// Values needed for dgesv
int n;
int nrhs = 1;
double a[MAX][MAX];
double b[1][MAX];
int lda = MAX;
int ldb = MAX;
int ipiv[MAX];
int info;
// Other values
int i,j;
// Read the values of the matrix
std::cout << "Enter n \n";
std::cin >> n;
std::cout << "On each line type a row of the matrix A followed by one element of b:\n";
for(i = 0; i < n; i++){
std::cout << "row " << i << " ";
for(j = 0; j < n; j++)std::cin >> a[j][i];
std::cin >> b[0][i];
}
// Solve the linear system
dgesv_(&n, &nrhs, &a[0][0], &lda, ipiv, &b[0][0], &ldb, &info);
// Check for success
if(info == 0)
{
// Write the answer
std::cout << "The answer is\n";
for(i = 0; i < n; i++)
std::cout << "b[" << i << "]\t" << b[0][i] << "\n";
}
else
{
// Write an error message
std::cerr << "dgesv returned error " << info << "\n";
}
return info;
}

