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++?