开发者

How to achieve symbol versioning

I want to achieve something like below :

I have multiple versions of a library. I dynamically load the latest version of the library using dlopen(). Then I want to see if a particular function (along with similar return type and argument list) exists in that version. If it does then open it else fall back to the previous version to check the same.

I've seen some posts on "version scripts" but am unable to use it. Also I think searching the symbol table will not be 开发者_Python百科a solution as it only checks for function name there.


Good explanation of symbol versioning is here. You need a dlvsym() function from GNU extension to search for a symbol by name and version:

#define _GNU_SOURCE
#include <dlfcn.h>
void *dlvsym(void *handle, char *symbol, char *version);

The function dlvsym() does the same as dlsym() but takes a version string as an additional argument. Note: C++ symbol names should be passed to dlvsym() in mangled form containing argument list. Unfortunately, GCC mangled name (unlike MSVC) doesn't contain a return type.

For more info see "dlopen(3) - Linux man page".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜