Tyler McMaster
Tyler McMaster

Reputation: 1407

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 info function.

Upvotes: 0

Views: 133

Answers (1)

Michael Anderson
Michael Anderson

Reputation: 73480

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/

Upvotes: 1

Related Questions