使用 dgesv_ 时出错:C:..眼动仪.exe未找到

Error when using dgesv_: C:...Eye Tracker.exe not found

本文关键字:exe 出错 dgesv 使用      更新时间:2023-10-16

我正在尝试使用dgesv_函数解决一个简单的问题Ax = b。但是,我遇到了一个我无法解决的问题。我的代码是:

#include <cstdio>
#include <f2c.h>
#include <clapack.h>
void main(void)
{
    /* 3x3 matrix A
     * 76 25 11
     * 27 89 51
     * 18 60 32
     */
    double A[9] = {76, 27, 18, 25, 89, 60, 11, 51, 32};
    double b[3] = {10, 7, 43};
    int N = 3;
    int nrhs = 1;
    int lda = 3;
    int ipiv[3];
    int ldb = 3;
    int info;
    dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);
}

我认为代码是正确的,但是,每当我运行它时,我都会收到以下错误:

LINK : C:...Eye Tracker.exe not found or not built by the last incremental link; performing full link
1>     Creating library C:...Eye TrackerDebugEye Tracker.lib and object C:UsersDanieldocumentsvisual studio 2010ProjectsEye TrackerDebugEye Tracker.exp
1>ellipse_fit.obj : error LNK2019: unresolved external symbol "void __cdecl dgesv_(int const *,int const *,double *,int const *,int *,double *,int const *,int *)" (?dgesv_@@YAXPBH0PAN0PAH102@Z) referenced in function "void __cdecl ttt(void)" (?ttt@@YAXXZ)
1>C:UsersDanieldocumentsvisual studio 2010ProjectsEye TrackerDebugEye Tracker.exe : fatal error LNK1120: 1 unresolved externals

您的错误可能来自 LAPACK 未链接到您的程序。CLAPACK 很容易链接到 C 程序,但链接到 C++ 需要添加几行。根据 http://wwwx.cs.unc.edu/~cquammen/wp/2010/08/12/calling-clapack-code-from-c/以下行应该可以解决问题:

extern "C" {
  #include <f2c.h>
  #include <clapack.h>
}

如果还不够,这里有一段可以通过g++ main.cpp -o main -llapack -lblas -lm编译的代码:

#include <iostream>
using namespace std;
extern "C"
{
void dgesv_(int* n,int* nrhs,double* a,int* lda,int* ipiv, double* b,int* ldb,int* info);
}
int main(void)
{
    /* 3x3 matrix A
     * 76 25 11
     * 27 89 51
     * 18 60 32
     */
    double A[9] = {1, 0, 0, 0, 2, 0, 0, 0,4};
    double b[3] = {42, 84, 168};
    int N = 3;
    int nrhs = 1;
    int lda = 3;
    int ipiv[3];
    int ldb = 3;
    int info;
    dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);
    cout<<"solution : "<<b[0]<<"  "<<b[1]<<"  "<<b[2]<<endl;
}