How to execute unknown functions from dynamic load libraries?
Posted
by activenightly
on Stack Overflow
See other posts from Stack Overflow
or by activenightly
Published on 2010-05-12T14:41:12Z
Indexed on
2010/05/12
14:44 UTC
Read the original article
Hit count: 178
It's easy to load functions from dynamic libraries when you know this function in design time. just do something like this:
int (*fn)(int);
l0 = dlopen("./libfoo.so", RTLD_LAZY);
if (!l0)
{
fprintf(stderr, "l0 %s\n", dlerror());
return 1;
}
fn = (int (*)(int))dlsym(l0, "foo");
if ((error = dlerror()) != NULL)
{
fprintf(stderr, "fn:%s\n", error);
return 1;
}
x=(*fn)(y);
...
How to execute library function when it's unknown in design time? In runtime you have a function name and array of arguments pointers and array of arguments sizes:
char* fn_name="foo"; int foo_argc; void* foo_argv[]; int foo_argv_size[];
In scripting language it's a piece a cake task, but how to implement this nicely in c++?
© Stack Overflow or respective owner