2

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?

Nikos C.
  • 50,738
  • 9
  • 71
  • 96
user1032861
  • 487
  • 3
  • 11
  • 19
  • I believe you that you can't have x.so on your development system, but I'm curious - why not? – gcbenison Jan 22 '13 at 15:19
  • Does this answer your question? [Is it possible to link to a shared library without access to the library itself?](https://stackoverflow.com/questions/45014588/is-it-possible-to-link-to-a-shared-library-without-access-to-the-library-itself) – user202729 Nov 18 '22 at 20:19

1 Answers1

2

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.

Nikos C.
  • 50,738
  • 9
  • 71
  • 96