freeinternet
freeinternet

Reputation: 9

How to use my c style func obtained by dlsym in my c++ program

SO basically i dont know hu use this funciton "createLib" i can't seem to be able to use it:

auto createLibFunc = dlsym(lib, symbol.c_str());

This works, i opened my dymacally loaded lib with dlopen, i can get functions symbols with dlsym but i dont know how to uanch ceateLibFunc(); after i fetched it, it should be something like createLibFunc(); as easy no? here's the createLibs func:

extern "C" IDisplayModule *createLib()
{
    return new LibNcurses();
}

Upvotes: 0

Views: 257

Answers (1)

rici
rici

Reputation: 241701

The most readable solution IMHO is to create a type alias:

extern "C" typedef IDisplayModule* CreateLibT();

Then you can use it to declare the type of your function pointer:

auto createLibFunc = reinterpret_cast<CreateLibT*>(dlsym(lib, symbol.c_str()));

Upvotes: 1

Related Questions