I want my executable to be “optionally dependent” on another shared object. Thus, it can work without some characters if there is no DSO.
I can achieve this with calls dlopen/dlsym, but I have to manually load each character and add wrappers for them as follows:
void *my_lib = dlopen("my_lib.so", RTLD_LAZY);
if (!my_lib) {
// ok, I promise not to touch my_lib symbols
} else {
my_foo_ptr = dlsym(my_lib, "my_foo");
my_bar_ptr = dlsym(my_lib, "my_bar");
}
... my_foo(...) {
assert(my_foo_ptr);
return (*my_foo_ptr)(...);
}
... my_bar(...) {
assert(my_foo_ptr);
return (*my_bar_ptr)(...);
}
This is dumb code, and it directly depends on the "my_lib.so" ABI, which means that I have to update it every time I update the library.
I am looking for a way to ld.sodo it for me. Thus, the ideal would be as follows:
void *my_lib = dlopen("my_lib.so", );
if (!my_lib) {
} else {
my_foo();
my_bar();
}
:
1. ? my_lib.so, my_lib.so. , ld undefined.
2. dlopen() my_lib.so ?
: , DT_NEEDED . , ld .