Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help to compile/link .so's with duplicate symbols

Status
Not open for further replies.

cspit

Programmer
Mar 28, 2003
1
MT
Would appreciate help in solving the following problem.

I have two simple shared libraries: TestA.so and TestB.so.
Both libraries have an exported function say_hello() that work as follows: TestA's say_hello() prints 'Hello from TestA', while TestB's say_hello() prints 'Hello from TestB'.
Moreover, the TestB library *imports* the TestA library.

Furthermore, I am using a simple main program that takes the library name as a command line parameter, opens the library using dlopen and attaches a function pointer to the say_hello function of the library specifed on the command line; the aim is to call TestA's say_hello when i specify TestA on the command line, and TestB's say_hello when TestB is specified on the command line, like this:

$ main.exe ./TestA
> hello from TestA

..and..

$ main.exe ./TestB
> hello from TestB

My problem is this: no matter which library i specify on the command line, the output i get is always the one from the TestA library, as shown:

$main.exe ./TestA
> hello from TestA

$main.exe ./TestB
> hello from TestA << problem! should be 'hello from TestB'

Is this because the say_hello function in TestB is overridden when i import the TestA library in it? I also tried specifying different linking priorities on linker when TestA is imported in TestB, but it didn;t solve the problem.

Is there a way of going around it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top