错误:变量的类型不完整'void'

时间:2015-06-29 01:46:18

标签: python c++ gcc

我正在Mac机器上编译c ++代码。我使用终端使用python运行安装文件。当我编译代码来生成.so文件时,我收到以下错误:

python setup.py build
running build
running build_ext
building 'cec13_func' extension
gcc -fno-strict-aliasing -fno-common -dynamic -arch x86_64 -DNDEBUG -g -O3 -arch x86_64 -I/Applications/Canopy.app/appdata/canopy-1.5.4.3105.macosx-x86_64/Canopy.app/Contents/include/python2.7 -c cec13_func.cpp -o build/temp.macosx-10.6-x86_64-2.7/cec13_func.o
cec13_func.cpp:91:6: error: variable has incomplete type 'void'
void test_func(x, f, nx, mx, func_num);<br>
     ^
cec13_func.cpp:92:1: error: expected unqualified-id
{
^
2 errors generated.
error: command 'gcc' failed with exit status 1

这是代码:

double x[6]={1,2,3,4,5,6};
double f[2]={0,0};
int nx = 2;
int mx = 3;
int func_num = 1;

void test_func(x, f, nx, mx, func_num)
{
    int cf_num=10,i;
    if (ini_flag==1)
    {
        if ((n_flag!=nx)||(func_flag!=func_num))
        {
            ini_flag=0;
        }
    }

    if (ini_flag==0)
    {
        FILE *fpt;
        char FileName[30];
        free(M);
        free(OShift);
        free(y);
        free(z);
        free(x_bound);
        y=(double *)malloc(sizeof(double)  *  nx);
        z=(double *)malloc(sizeof(double)  *  nx);
        x_bound=(double *)malloc(sizeof(double)  *  nx);
        for (i=0; i<nx; i++)
            x_bound[i]=100.0;

        sprintf(FileName, "input_data/M_D%d.txt", nx);
        fpt = fopen(FileName,"r");
        if (fpt==NULL)
        {
            printf("\n Error: Cannot open input file for reading \n");
        }

        M=(double*)malloc(cf_num*nx*nx*sizeof(double));
        if (M==NULL)
            printf("\nError: there is insufficient memory available!\n");
        for (i=0; i<cf_num*nx*nx; i++)
        {
                fscanf(fpt,"%Lf",&M[i]);
        }
        fclose(fpt);


        fpt=fopen("input_data/shift_data.txt","r");
        if (fpt==NULL)
        {
            printf("\n Error: Cannot open input file for reading \n");
        }
        OShift=(double *)malloc(nx*cf_num*sizeof(double));
        if (OShift==NULL)
            printf("\nError: there is insufficient memory available!\n");
        for(i=0;i<cf_num*nx;i++)
        {
                fscanf(fpt,"%Lf",&OShift[i]);
        }
        fclose(fpt);

        n_flag=nx;
        func_flag=func_num;
        ini_flag=1;
        //printf("Function has been initialized!\n");
    }


    for (i = 0; i < mx; i++)
    {
        switch(func_num)
        {
        case 1: 
            sphere_func(&x[i*nx],&f[i],nx,OShift,M,0);
            f[i]+=-1400.0;
            break;
        case 2: 
            ellips_func(&x[i*nx],&f[i],nx,OShift,M,1);
            f[i]+=-1300.0;
            break;
        default:
            printf("\nError: There are only 28 test functions in this test suite!\n");
            f[i] = 0.0;
            break;
        }   
    }
}

我需要一些建议。 谢谢!

1 个答案:

答案 0 :(得分:6)

此...

void test_func(x, f, nx, mx, func_num)

...完全崩溃:函数参数需要指定两者数据类型(例如intdoubleconst char*)和标识符。稍后使用这些标识符意味着它们是变量名称,而不是struct / class / union / enumtypedef名称),所以它是<缺少的em> types 。

进一步令人困惑的事情,文件顶部有:

double x[6]={1,2,3,4,5,6};
double f[2]={0,0};
int nx = 2;
int mx = 3;
int func_num = 1;

这些名称与test_func函数参数的名称相同。也许您想将它们放在调用test_func的函数中,然后在调用期间传递它们?或者 - 更简单但更不灵活 - 如果test_func只需要使用这些特定参数运行,您可以将它们放在test_func主体的开头,并将参数列表留空(即{{1 }})。

最后,您的文件扩展名为test_func() - 暗示C ++,但您的编译行正在使用{C}的.cpp。代码本身看起来它只使用C ++的C子集,而不是这意味着您无法使用gcc进行编译。