void* l = dlsym(lib,"_ZN11Environment9LibLogger14log_processingEiNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEjS6_z");
*(void **)&log_fcn = l;
std::cout<<"Address"<<<<l<<"LOG_FCN "<<log_fcn<<std::endl;
I am trying to print address of l and log_fcn but both are not same. Why is that, and how can I get address of dlsym assign to function pointer?
Output example:
l= 0x7efe10eabaa0 LOG_FCN 1
void (*log_fcn)(int level, std::string frmt, unsigned int line_no, std::string file_name, ...); function decleration
There is an
operator <<forvoid*, but not for function pointers.Function pointers are implicitly converted to
bool, notvoid*, andboolprints as0or1by default.Your
1output indicates thatlog_fcnis not the null pointer.Convert it when printing:
I would recommend that you also do the assignment in the conventional form, by casting the right-hand side: