You will get a segmentation fault when
i
is
NULL
. Check if loading the library and getting the symbol was successful:
CLASS_NAME * i = NULL;
void * h = dlopen("./LIBNAME.so",RTLD_NOW);
char *err = dlerror();
if (!h)
{
}
else
{
i = (CLASS_NAME *)dlsym(h, "CLASS_NAME");
if ((err = dlerror()) != NULL)
{
}
else if (i)
{
i->Create(1);
}
}
See also
dlopen(3) - Linux man page[
^].
Is there any specific reason that you are using dynamic loading? If not, just link your application with the library.