开发者

How to achieve symbol versioning

开发者 https://www.devze.com 2023-02-10 15:24 出处:网络
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

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

精彩评论

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