views:

33

answers:

2

Hi,

I am using a third party shared library and I need to check whether a function is exported by shared library programatically.

How to do this. I need this because if function does not exist I need to run some other function locally.

+1  A: 

You could probably use dlsym for this.

If you load the library with dlopen, you will use the handle that it returns.

If you're linked against this library you may use special pseudo-handles (10x to caf for pointing it out):

From dlsym man:

There are two special pseudo-handles, RTLD_DEFAULT and RTLD_NEXT. The former will find the first occurrence of the desired symbol using the default library search order. The latter will find the next occurrence of a function in the search order after the current library. This allows one to provide a wrapper around a function in another shared library.

Dmitry Yudakov
On Linux you don't need to open it with `dlopen()` - if the target library is linked against the main program, you can pass the pseudo-handle `RTLD_DEFAULT` to `dlsym()`.
caf
it's a good note, thank you. I'll edit my answer
Dmitry Yudakov
This solves my problem, thank you
siri
A: 

Check the header file of the intended library to get the function signature. Using dlopen you can load the library dynamically and fetch the symbol if it is exposed in the library with subsequent calls to dlsym and dlclose.

Praveen S