knifecentipede
knifecentipede

Reputation: 53

dlsym - "Too many arguments to function" error

I am doing a C exercise that involves loading a shared library dynamically. When I compile my test program using gcc -o test2 test2.c -ldl command, I get an error:

test2.c: In function ‘main’:
test2.c:27:5: error: too many arguments to function ‘test’
    (*test)(array, size);

This is the bit where I get the error:

void (*test)(void);    
test = dlsym(handle, "lib_fill_random");
(*test)(array, size);

lib_fill_random is declared with two arguments in both in .h and .c files as void lib_fill_random(double *array, int size);, and it works perfectly fine by itself.

What could be causing this issue?

Upvotes: 0

Views: 1535

Answers (1)

Barmar
Barmar

Reputation: 781340

The function pointer declaration has to match the declaration of the actual function. So it should be:

void (*test)(double *, int);

Your declaration states that the function takes no arguments, so you get an error when you call it with arguments.

Upvotes: 1

Related Questions