How do i call an external function?
I have code i'm trying to write, I have a void function, info.
void info(char *,char *);
This, I'm trying to call from my main function in a separate file. I want to use dlopen to open a so file. How would i call the function: info. From my other file?
I'm trying to use
info("testing: ","Success");
I get an undefined reference error on my in开发者_如何学Gofo function.
The usual path is something like this:
/* Set up a typedef for the function pointer to make the code nicer */
tyepdef void(*Info_ptr)(char*, char*);
/* Get the function, lib must be the dlopened library.*/
Info_ptr info;
info = (Info_ptr)dlsym( lib, "info");
/* Use the function pointer */
(*info)("testing: ", "Success");
Take al ook here for a tute: http://tldp.org/HOWTO/html_single/C++-dlopen/
精彩评论