dlls containing functions with same names problems

Discussion in 'C Programming' started by stenasc@yahoo.com, Jun 28, 2007.

  1. Guest

    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
    , Jun 28, 2007
    #1
    1. Advertising

  2. Chris Dollin Guest

    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
    Chris Dollin, Jun 28, 2007
    #2
    1. Advertising

  3. 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 ]
    Roberto Waltman, Jun 28, 2007
    #3
  4. Guest

    On Jun 28, 3:02 pm, Roberto Waltman <> wrote:
    > 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 -
    , Jun 28, 2007
    #4
  5. 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
    Richard Heathfield, Jun 28, 2007
    #5
  6. CBFalconer Guest

    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
    CBFalconer, Jun 28, 2007
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shaun duke
    Replies:
    2
    Views:
    534
    shaun duke
    Mar 24, 2005
  2. Chris Pudney
    Replies:
    1
    Views:
    815
    Chris Pudney
    Dec 5, 2003
  3. newdaddy
    Replies:
    5
    Views:
    757
  4. John O'Hagan
    Replies:
    2
    Views:
    265
    John O'Hagan
    Nov 1, 2008
  5. Kodiak
    Replies:
    3
    Views:
    392
    Malcolm McLean
    Jul 13, 2012
Loading...

Share This Page