user1032861
user1032861

Reputation: 527

Link shared library in gcc without file?

Let's say I have a x.so library on my target system that I can't have on my development system.

I need to compile, using gcc, a program on my development machine that runs on the target machine using that x.so.

Is there any way to do this?

Upvotes: 2

Views: 247

Answers (1)

Nikos C.
Nikos C.

Reputation: 51842

Yes. You don't link against that library at all, but rather open it with dlopen():

void* dlhandle = dlopen("x.so", RTLD_LAZY);

and load symbols from it using dlsym():

some_func_pointer = dlsym(dlhandle, "function");

You can then call function() through the function pointer you get from dlsym(). The type of the function pointer must of course match the function you're loading. It is not checked for you.

Upvotes: 2

Related Questions