error: void value not ignored as it ought to be

2k Views Asked by At

I am trying to get function symbol from a dynamic library and then I need to replace my function with the library funciton using the new function pointer.The code is to be written in c++ file.

I used following steps,

{
void *temp = dlsym(<FLAGS>,<FUNC_NAME>);
*reinterpret_cast<void**>(&real_mal) = temp;
void *p = NULL;
p = real_mal(size);
return p;
}

But at compile time I am getting this "error: void value not ignored as it ought to be " error

How can I resolve above situation ?

Thanks

1

There are 1 best solutions below

0
On

Joachim's comment is right. The first problem is actually your cast. The proper cast is real_mal = reinterpret_cast<void*(size_t)>(dlsym(<FLAGS>,<FUNC_NAME>));. Your current cast hides the incorrect declaration of real_mal.

Once you've fixed that, you can just write return real_mal(size);.