我正在做一个涉及动态加载共享库的C练习。当我使用gcc -o test2 test2.c -ldl
命令编译我的测试程序时,出现错误:
test2.c: In function ‘main’:
test2.c:27:5: error: too many arguments to function ‘test’
(*test)(array, size);
这是我收到错误的地方:
void (*test)(void);
test = dlsym(handle, "lib_fill_random");
(*test)(array, size);
lib_fill_random
在.h和.c文件中声明为void lib_fill_random(double *array, int size);
两个参数,并且它本身完全正常。
可能导致此问题的原因是什么?
答案 0 :(得分:1)
函数指针声明必须与实际函数的声明匹配。所以它应该是:
void (*test)(double *, int);
您的声明声明该函数不带参数,因此在使用参数调用它时会出错。