首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用dgesv_时出错: C:\...\Eye Tracker.exe not found

使用dgesv_时出错: C:\...\Eye Tracker.exe not found
EN

Stack Overflow用户
提问于 2014-02-11 21:41:00
回答 1查看 846关注 0票数 3

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

代码语言:javascript
复制
#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);

}

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

代码语言:javascript
复制
LINK : C:\...\Eye Tracker.exe not found or not built by the last incremental link; performing full link
1>     Creating library C:\...\Eye Tracker\Debug\Eye Tracker.lib and object C:\Users\Daniel\documents\visual studio 2010\Projects\Eye Tracker\Debug\Eye 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:\Users\Daniel\documents\visual studio 2010\Projects\Eye Tracker\Debug\Eye Tracker.exe : fatal error LNK1120: 1 unresolved externals
EN

回答 1

Stack Overflow用户

发布于 2015-02-21 00:48:29

您的错误可能来自于LAPACK没有链接到您的程序。CLAPACK很容易链接到C程序,但链接到C++需要添加几行代码。根据http://wwwx.cs.unc.edu/~cquammen/wp/2010/08/12/calling-clapack-code-from-c/的说法,下面这几行应该可以做到这一点:

代码语言:javascript
复制
extern "C" {
  #include <f2c.h>
  #include <clapack.h>
}

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

代码语言:javascript
复制
#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;
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21703508

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档