- #1

pasmith

Homework Helper

- 1,754

- 424

## Main Question or Discussion Point

I get an 'undefined reference to 'zcgesv_'' error when I try to link the LAPACK library using g++ on cygwin64.

What am I missing? Google has not turned up anything which solves the problem.

(Documentation for zcgesv here )

My Makefile is as follows:

lapacktest.cpp contains the following:

What am I missing? Google has not turned up anything which solves the problem.

(Documentation for zcgesv here )

My Makefile is as follows:

Code:

```
GCC := /usr/bin/i686-pc-cygwin-g++
LIBS := -L/usr/lib -llapack -lblas
lapacktest.o: lapacktest.cpp
$(GCC) -c -o lapacktest.o lapacktest.cpp
lapacktest.exe: lapacktest.o
$(GCC) -o lapacktest.exe $(LIBS) lapacktest.o
```

Code:

```
#include<iostream>
using namespace std;
typedef struct{double real;double imag;} Complex;
extern "C"
void zcgesv_(
int*, // N
int*, // NRHS
Complex*, // A
int*, // LDA
int*, // IPIV
Complex*, // B
int*, // LDB
Complex*, // X
int*, // LDX
Complex*, // WORK
Complex*, // SWORK
double*, // RWORK
int*, // ITER
int* // INFO
);
int main(int argc, char *argv[])
{
Complex *A, *b, *x, *work, *swork;
double * rwork;
int n, nrhs, lda, ldb, ldx, iter, info, *ipiv;
int i,j;
n = 3;
nrhs = 1;
lda = ldb = ldx = n;
A = new Complex[n*n];
b = new Complex[n*nrhs];
x = new Complex[n*nrhs];
ipiv = new int[n];
work = new Complex[n*nrhs];
swork = new Complex[n*(n+nrhs)];
rwork = new double[n];
for(i = 0; i < n; i++)
{
b[i] = Complex{1.0,0.0};
// The matrix I'm interested in is neither diagonal nor sparse, but this is a simple test.
for(j = 0; j < n; j++)
A[n*j + i] = (i == j) ? Complex{2.0,1.0} : Complex{0,0};
}
zcgesv_(&n,&nrhs, A, &lda, ipiv, b, &ldb, x, &ldx, work, swork, rwork, &iter, &info);
for(i = 0; i < n; i++)
cout << "(" << x[i].real << "," << x[i].imag << ")" << endl;
delete[] A;
delete[] b;
delete[] x;
delete[] work;
delete[] swork;
delete[] rwork;
delete[] ipiv;
return 0;
}
```