Is there a way to get an extern variable (or function) by name
I thought I read about a C standard library function recently that was able to return a pointer to any extern variable whose name was passed to it as a const char *. I think that it works via linker symbols开发者_如何转开发, if that helps.
You could be thinking of dlsym
, which is not part of the C standard library but part of the POSIX API.
It depends on the system. dlsym
has already been mentioned. Its Windows counterpart is GetProcAddress
. In the latter case, the function needs to be not only external but exported.
精彩评论