Sirish Kumar Bethala
Sirish Kumar Bethala

Reputation: 9259

How to check Shared Library exposed functions in program

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.

Upvotes: 3

Views: 3060

Answers (3)

ASB
ASB

Reputation: 344

may be you can use objdump command to check all symbol exposed like this objdump -T libtest.so

Upvotes: 1

Dmitry Yudakov
Dmitry Yudakov

Reputation: 15734

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.

Upvotes: 2

Praveen S
Praveen S

Reputation: 10395

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.

Upvotes: 0

Related Questions