在cygwin下链接错误与LAPACK

时间:2015-06-10 17:03:55

标签: c++ cygwin lapack

this question中描述的问题类似,我想使用cygwin(用NetBeans编写)在Windows 8.1下使用LAPACK编译C ++程序。我在cygwin(lapack,liblapack-devel,liblapack0)中获得了必要的包,并编写了一个函数原型:

extern "C" void dgeev_(char* jobvl, char* jobvr, int* n, double* a,
    int* lda, double* wr, double* wi, double* vl, int* ldvl,
    double* vr, int* ldvr, double* work, int* lwork, int* info);

但是尝试编译仍然会从链接器中抛出错误:

$ g++ -llapack -lblas main.cpp 
/tmp/cc3opfN5.o:main.cpp:(.text+0x349): undefined reference to `dgeev_'
/tmp/cc3opfN5.o:main.cpp:(.text+0x403): undefined reference to `dgeev_'
collect2: error: ld returned 1 exit status

代码看起来像这样(改编自this example):

/* Locals */
int n = N, lda = LDA, ldvl = LDVL, ldvr = LDVR, info, lwork;
double wkopt;
double* work;
double h = k_max / N;
/* Local arrays */
double wr[N], wi[N], vl[LDVL * N], vr[LDVR * N];
double a[LDA * N];
/* Initialize matrix */
for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
        a[i * N + j] = integral(i + 1, j + 1);
        if (i == j) {
            a[i * N + j] += diagonal((i + 1) * h);
        }
    }
}
/* Executable statements */
printf(" DGEEV Example Program Results\n");
/* Query and allocate the optimal workspace */
lwork = -1;
char vec[] = "Vectors";
dgeev_(vec, vec, &n, a, &lda, wr, wi, vl, &ldvl, vr, &ldvr,
        &wkopt, &lwork, &info);
lwork = (int) wkopt;
work = (double*) malloc(lwork * sizeof (double));
/* Solve eigenproblem */
dgeev_(vec, vec, &n, a, &lda, wr, wi, vl, &ldvl, vr, &ldvr,
        work, &lwork, &info);

我错过了什么? : - /

1 个答案:

答案 0 :(得分:0)

假设您已正确安装了BLASLAPACK库,并且系统可以找到它们,那么您只需更改编译命令中的顺序。

$ g++ main.cpp -llapack -lblas

在声明它们之前,编译器应该知道main.cpp的哪些函数应该查看库。