I have a shared library (more precisely a PKCS#11 module) and I want to write an application that can load a library and use it.
Currently I'm using dlsym like this:
My_C_GetSlotList = (CK_C_GetSlotList) dlsym (module, "C_GetSlotList");
if (!My_C_GetSlotList) printf("Couldn't find function 'C_GetSlotList' in library: %s: %s\n", filename, dlerror ());
But the library does have about 68 functions. I guess the real question is: Do I really have to do this for every functions? Is there a struct with a list of all functions? Maybe I'm just using dlsym wrong ...
You need to use dlsym() only once to acquire function pointer for C_GetFunctionList() function which will return you structure with pointers to all the other functions.
You can find example code on page 106 in PKCS#11 v2.20 specification.