-3

I want to Link two .so with each other. Scenario is : 1) A method(Ex. void fun() ) with same name are defined in both .so 2) suppose we are calling this method from first .so then call should go to method defined in 2nd .so

How is this possible?

// Module 2

#include <stdio.h>
void fun();

void fun()
{
   printf(""from 2nd .so\n"");
}


// Module 1 

#include <stdio.h>
void fun();

void fun()
{
   printf("from 1st .so\n");
}

int main()
{
  fun();
  return 0;
}
Anton Savin
  • 40,838
  • 8
  • 54
  • 90
anp4355
  • 21
  • 2

3 Answers3

0

If you really want this I think you can handle this with delay load of the libraries.

Here is an example in unix: Delay-Load equivalent in unix based systems

Community
  • 1
  • 1
Biber
  • 709
  • 6
  • 19
0

You will get conflict with names, this is one of the reasons you have namespaces in c++ and since you marked your question with c++ tag also, so I assume you can compile in this language. Delayed load of shared lib is also some kind of solution, but you will have to manually check symbols + dependecy to library opened by dlopen won't be shown by ldd command (or equivalent on windows). You can also check some tricks proposed here:

linking two shared libraries with some of the same symbols

I hope you are asking about this only because you are working with legacy code and code you posted is only example. You shouldn't be doing things like this deliberately.

Community
  • 1
  • 1
Kuba
  • 839
  • 7
  • 16
0

Not possible, in the example given. When the second .so is built, the call to fun() is already resolved. You can't re-resolve a call.

MSalters
  • 173,980
  • 10
  • 155
  • 350