18-12-2018, 12:07 PM
I think the behavior of explicit dynamic linking with dlopen/dlsym is undefined if the function signature does not match:
I would always prefer implicit dynamic linking (e.g. -llibrary) because of the type checking involved.
Code:
int (*ptr)(void) = static_cast(dlsym(handle, "func"));// no way to check the return value e.g. the signature of func
if (ptr != nullptr)
ptr();// undefined behavior if func is not defined as int func(void) inside the shared object
I would always prefer implicit dynamic linking (e.g. -llibrary) because of the type checking involved.
<t></t>