c - 调用 CLAPACK 函数后变量初始化

标签 c visual-studio-2008 lapack

我最近设法构建并运行了一个简单的 CLAPACK Microsoft Visual Studio 2008 项目(从 http://icl.cs.utk.edu/lapack-for-windows/lapack/index.html 下载)。之后,在 LAPACK dgesv_ 调用后插入一行以初始化另一个整数 tempInteger 会导致构建失败。错误是:CLAPACK-EXAMPLE.c(30):错误 C2143:语法错误:缺少“;”在“类型”之前。看起来 LAPACK 函数的执行阻止了某些操作,例如之后的变量初始化。谁能帮我了解发生了什么并解决它?提前致谢。代码 list 如下:

#include < stdio.h>
#include "f2c.h"
#include "clapack.h"

int 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;
    int qqq = 1;

    dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);

    if(info == 0) /* succeed */
    printf("The solution is %lf %lf %lf\n", b[0], b[1], b[2]);
    else
    fprintf(stderr, "dgesv_ fails %d\n", info);

    int tempInteger = 1;

    return info;
}

最佳答案

如果此文件编译为 C 文件而不是 C++ 文件,则应在函数顶部声明 tempInteger 类型。 例如:

#include < stdio.h>
#include "f2c.h"
#include "clapack.h"

int 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;
    int qqq = 1;
    int tempInteger;

    dgesv_(&N, &nrhs, A, &lda, ipiv, b, &ldb, &info);

    if(info == 0) /* succeed */
    printf("The solution is %lf %lf %lf\n", b[0], b[1], b[2]);
    else
    fprintf(stderr, "dgesv_ fails %d\n", info);

    tempInteger = 1;

    return info;
}

关于c - 调用 CLAPACK 函数后变量初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18396025/

相关文章:

c++ - 是否有一种算法可以将 LAPACK 排列更改为真实排列?

在 GNU/Linux 上从 C 中的 LAPACK 调用 DPOTRS

在普通的旧 C 中将字节数组转换为十六进制字符串

c - 如何用比例而不是原始数字显示文本直方图

c++ - 程序在我的机器上运行 2 秒,但在其他机器上运行 15 秒

c++ - 为什么我不能在 VS2008 的类中使用静态成员,例如静态结构?

c++ - 避免 LAPACK 中的矩阵半矢量化

c - Linux套接字程序中的recvfrom api

c - 如何在不使用循环的情况下在 C 中初始化 N 维数组

visual-studio - Visual Studio 和 Temp 文件夹的病毒扫描