开发者

Still reports "undefined symbol: new_add" after use "objcopy --redefine-sym add=new_ad"

I need to load two dynamic libraries and there is one function name confliction. So I use the the command "objcopy --redefine-sym add=new_add libmy_test.so libmy_test_new.so" to modify the symbol name.

But it still reports "Error: ./libmy_test_new.so开发者_如何学运维: undefined symbol: new_add"

The following are my test codes.

void *lib_handle2 = dlopen("./libmy_test_new.so", RTLD_NOW);
if (NULL == lib_handle2) {
    printf("Error: %s\n", dlerror());
    goto err1;
}

fp_add f_add2 = dlsym(lib_handle2, "new_add");
if (NULL == f_add2) {
    printf("Error: %s\n", dlerror());
    goto err2;
}


According to this page, it seems it does not work with dynamic symbol. More explanation are available in the original thread. If you want to use both symbol, then you somehow need to relink one of the libraries. However if you want only one of the symbol, then linking order might help you.

Maybe the solution is creating a wrapper library, in which you dlsopen the two libs, create two new symbol, and assign them using dlsym with the correct handle.

void *lib_handle1 = dlopen("./lib1.so", RTLD_NOW);
void *lib_handle2 = dlopen("./lib2.so", RTLD_NOW);

fp_add f_add1 = dlsym((lib_handle1, "add");
fp_add f_add2 = dlsym(lib_handle2, "add");

Of course it does not solve the problem of call generated inside the libraries.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜