gpt4 book ai didi

python - 错误 : variable has incomplete type 'void'

转载 作者:太空宇宙 更新时间:2023-11-04 15:36:54 26 4
gpt4 key购买 nike

我正在我的 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;
}
}
}

我需要一些建议。谢谢!

最佳答案

这...

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

...完全损坏:函数参数需要指定两者数据类型(例如intdoubleconst char*) 和一个标识符。这些标识符的后续用法意味着它们是变量名,而不是 struct/class/union/enumtypedef 名称),因此缺少类型

更令人困惑的是,文件顶部有:

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 主体的开头,并保留参数列表空(即 test_func())。

最后,您的文件扩展名是 .cpp - 暗示 C++,但您的编译行使用的是用于 C 的 gcc。代码本身看起来只使用了C++ 的 C 子集,但这并不意味着您不能使用 g++ 编译它。

关于python - 错误 : variable has incomplete type 'void' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31106666/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com