dlls containing functions with same names problems

S

stenasc

Hi,

I have created an C based application in linux that uses a number of
dlls. Within the dlls themselves, the code calls sub functions e.g

dll_1 (Main dll function is called Return_Answer. The code within the
Return_Answer function called another function called Timer which is
in dll_1)

dll2 (Main dll function is called Calculate_Best_Result. The code
within the Calculate_Best_Result function called another function
called Timer which is in dll_2)

The Timer functions in each dll are completely different. However,
when I debug dll_1 in gdb, and am stepping through the code, I see
that it jumps to the dll_2 Timer function instead of it's own.

Anyone got any ideas. I have the same code working fine in MSVC. Never
had a problem with it. The commands, I use to compile and link to the
main executable are...

gcc -ggdb -c -fPIC dll_1.c
gcc -ggdb -shared -o libdll_1.so dll_1.o

gcc -ggdb -c -fPIC dll_2.c
gcc -ggdb -shared -o libdll_2.so dll_2.o

The main code file is called test.c

gcc -ggdb -c test.c
gcc -o test -lm test.o -L. -ldll_1 -ldll_2 -ldl

Everything compiles and links fine, so I am at a loss. Any help is
much appreciated.

Regards
Bob
 
C

Chris Dollin

I have created an C based application in linux that uses a number of
dlls. Within the dlls themselves, the code calls sub functions e.g

dll's aren't part of C; they're an OS-specific extension.

I'd start in comp.unix.programmer.
 
R

Roberto Waltman

I have created an C based application in linux that uses a number of
dlls. Within the dlls themselves, the code calls sub functions e.g

dll_1 (Main dll function is called Return_Answer. The code within the
Return_Answer function called another function called Timer which is
in dll_1)

dll2 (Main dll function is called Calculate_Best_Result. The code
within the Calculate_Best_Result function called another function
called Timer which is in dll_2)

The Timer functions in each dll are completely different. However,
when I debug dll_1 in gdb, and am stepping through the code, I see
that it jumps to the dll_2 Timer function instead of it's own.
...

[Off-topic] 'DLL's (Dynamic Load Libraries) is a Windowism.
Linux has "shared libraries', VMS has 'resident libraries' and so on.

[Partially on-topic] Some aspects of code libraries design are
independent of the implementation.

Two (partially overlapping) theories:

(a) Under windows, (at least Windows-CE, which my employer is now
inflicting upon me,) a C function in a library in not visible to
outside code unless it is explicitly exported.
If the Timer() functions are not exported, a reference to one of them
from a library function must use the version defined in the same
library.
In a regular Linux shared library, all non-static functions are
visible, so it is possible to link to the wrong one.
If these functions are not required outside their libraries, it may be
possible to declare them as static and include them in the same file
as the functions calling them.

(b) All functions are visible in both environments, but when there are
duplicated symbols in two libraries, the Windows linker will favor
resolving references using functions from the same library first,
while ld in Linux will use a fixed order based on the ordering of the
files.
In this case rename the functions to Timer_Arctic() and
Timer_Antarctic(). (Other names may also work... ;) )

As already pointed out, try asking in comp.unix.programming,
comp.os.linux.development.apps or similar groups.


Roberto Waltman

[ Please reply to the group,
return address is invalid ]
 
S

stenasc

I have created an C based application in linux that uses a number of
dlls. Within the dlls themselves, the code calls sub functions e.g
dll_1 (Main dll function is called Return_Answer. The code within the
Return_Answer function called another function called Timer which is
in dll_1)
dll2 (Main dll function is called Calculate_Best_Result. The code
within the Calculate_Best_Result function called another function
called Timer which is in dll_2)
The Timer functions in each dll are completely different. However,
when I debug dll_1 in gdb, and am stepping through the code, I see
that it jumps to the dll_2 Timer function instead of it's own.
...

[Off-topic] 'DLL's (Dynamic Load Libraries) is a Windowism.
Linux has "shared libraries', VMS has 'resident libraries' and so on.

[Partially on-topic] Some aspects of code libraries design are
independent of the implementation.

Two (partially overlapping) theories:

(a) Under windows, (at least Windows-CE, which my employer is now
inflicting upon me,) a C function in a library in not visible to
outside code unless it is explicitly exported.
If the Timer() functions are not exported, a reference to one of them
from a library function must use the version defined in the same
library.
In a regular Linux shared library, all non-static functions are
visible, so it is possible to link to the wrong one.
If these functions are not required outside their libraries, it may be
possible to declare them as static and include them in the same file
as the functions calling them.

(b) All functions are visible in both environments, but when there are
duplicated symbols in two libraries, the Windows linker will favor
resolving references using functions from the same library first,
while ld in Linux will use a fixed order based on the ordering of the
Thanks for the suggestions...I'll post to the mentioned groups.

Bob
files.
In this case rename the functions to Timer_Arctic() and
Timer_Antarctic(). (Other names may also work... ;) )

As already pointed out, try asking in comp.unix.programming,
comp.os.linux.development.apps or similar groups.

Roberto Waltman

[ Please reply to the group,
return address is invalid ]- Hide quoted text -

- Show quoted text -
 
R

Richard Heathfield

Roberto Waltman said:

(a) Under windows, (at least Windows-CE, which my employer is now
inflicting upon me,) a C function in a library in not visible to
outside code unless it is explicitly exported.

How strange. I've written quite a few programs under Windows that can
call C functions in libraries just fine, without their being explicitly
exported. Perhaps this is a Wince-only phenomenon, and perhaps you're
simply mistaken, or perhaps I'm misinterpreting your statement, or
perhaps my memory is shot to pieces and I'm wrong, or perhaps there's
some other explanation. How to find out the truth? Ask in a Windows
programming group, that's how.
 
C

CBFalconer

I have created an C based application in linux that uses a number of
dlls. Within the dlls themselves, the code calls sub functions e.g

dll_1 (Main dll function is called Return_Answer. The code within the
Return_Answer function called another function called Timer which is
in dll_1)

dll2 (Main dll function is called Calculate_Best_Result. The code
within the Calculate_Best_Result function called another function
called Timer which is in dll_2)

The Timer functions in each dll are completely different. However,
when I debug dll_1 in gdb, and am stepping through the code, I see
that it jumps to the dll_2 Timer function instead of it's own.

Anyone got any ideas. I have the same code working fine in MSVC. Never
had a problem with it. The commands, I use to compile and link to the
main executable are...

Make the functions static.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top