1

我需要加载两个动态库,并且存在一个函数名冲突。所以我使用命令“objcopy --redefine-sym add=new_add libmy_test.so libmy_test_new.so”来修改符号名称。

但它仍然报告“错误:./libmy_test_new.so:未定义符号:new_add”

以下是我的测试代码。

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;
}
4

1 回答 1

2

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.

于 2010-10-13T07:20:15.357 回答