1

I recently managed to build and run a simple CLAPACK Microsoft Visual Studio 2008 project (downloaded from http://icl.cs.utk.edu/lapack-for-windows/lapack/index.html). After that, inserting a single line after LAPACK dgesv_ call to initialize another integer tempInteger leads to the unsuccessful build. The error is: CLAPACK-EXAMPLE.c(30) : error C2143: syntax error : missing ';' before 'type'. It appears that execution of LAPACK function prevents certain actions such as variable initialization afterwards. Could anyone help me understand what's going on and fix it? Thanks in advance. The code listing is below:

#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;
}
4

1 回答 1

0

如果此文件编译为 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;
}
于 2013-08-23T08:02:20.103 回答