I need to open multiple shared libraries at run time. I don’t know their number(count), so I am using dynamic memory allocation:
void* handle= new void* [n]; // n refers to number of handles
handle[0] = dlopen("./fileN.so", RTLD_LAZY); // doesn't work : Error: ‘void*’ is not a pointer-to-object type
However if I do static allocation, it works-
void* handle[10];
handle[0] = dlopen("./file0.so", RTLD_LAZY); // works
Why is that when I am dynamically accessing the handle, I am getting error? and how do I fix it?
You need an extra level of indirection. A pointer to a pointer:
Your code would be invalid on another type:
But it works with
void*asvoid*can point tovoid**.