dlls containing functions with same names problems

  • Follow


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

0
Reply stenasc (63) 6/28/2007 9:29:59 AM

 stenasc@yahoo.com wrote:

> 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.

-- 
Chris "surely you /expect/ problems with a two-Timer?" Dollin

Hewlett-Packard Limited                                          registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN          690597 England

0
Reply chris.dollin (1683) 6/28/2007 12:36:51 PM


stenasc@yahoo.com wrote:
>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 ]
0
Reply usenet35 (530) 6/28/2007 2:02:14 PM

On Jun 28, 3:02 pm, Roberto Waltman <use...@rwaltman.net> wrote:
> sten...@yahoo.com wrote:
> >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 -


0
Reply stenasc (63) 6/28/2007 2:55:49 PM

Roberto Waltman said:

<snip>
 
> (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.

-- 
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
0
Reply rjh (10789) 6/28/2007 3:38:45 PM

stenasc@yahoo.com wrote:
> 
> 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.

-- 
 <http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
 <http://www.securityfocus.com/columnists/423>
 <http://www.aaxnet.com/editor/edit043.html>
                        cbfalconer at maineline dot net



-- 
Posted via a free Usenet account from http://www.teranews.com

0
Reply cbfalconer (19183) 6/28/2007 4:25:30 PM

5 Replies
23 Views

(page loaded in 0.107 seconds)


Reply: