0

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.

2
  • 1
    "Undefined reference" is a linker error, not a compiler error. Reread about the basics of compiling and linking to double check how to link all your translation units. Commented Aug 29, 2011 at 0:50
  • The signature of the function does not provide enough information to say how to call it. However, if you don't know the function's requirements, then you should not use it. So the solution is, don't. Commented Aug 29, 2011 at 0:57

1 Answer 1

1

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/

Sign up to request clarification or add additional context in comments.

3 Comments

I found out that now its saying 'undefined symbol: info'
Check your .so to make sure you've got the symbol you expect in it. YOu can use nm to help you with that. If your info function is C++ too, then you'll need to set it up using extern "C" like in the tutorial.
Thanks for this, It helped me allot once i fixed the function info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.