Unresolved Symbols from C++ Code

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Scott Brady Drummonds

    Unresolved Symbols from C++ Code

    Hi, everyone,

    I'm writing a bunch of C++ code that is going to be linked into a program
    compiled with gcc (version 2.96; I have no option of changing this version).
    My C++ code compiles and executes without error in my C++ test harness.
    However, things fail once I move to gcc.

    Specifically, I'm getting errors like the following:

    vcs.o(.text+0xf ): undefined reference to `operator new(unsigned)'
    vcs.o(.text+0x4 9): undefined reference to `operator delete(void*)'
    vcs.o(.text+0x5 a): undefined reference to `_Unwind_Resume '
    vcs.o(.text+0x6 b): undefined reference to `operator delete(void*)'
    vcs.o(.text+0xa 9): undefined reference to `_Unwind_Resume '
    vcs.o(.text+0x1 49): undefined reference to
    `std::allocator <char>::allocat or()'
    vcs.o(.text+0x1 5f): undefined reference to `std::string::s tring(char const*,
    std::allocator< char> const&)'
    vcs.o(.text+0x1 89): undefined reference to `std::string::~ string()'
    vcs.o(.text+0x1 99): undefined reference to `std::string::~ string()'
    vcs.o(.text+0x1 ac): undefined reference to
    `std::allocator <char>::~alloca tor()'
    vcs.o(.text+0x1 bc): undefined reference to
    `std::allocator <char>::~alloca tor()'
    ....
    /usr/users/home4/sdrummon/src/marple/src/vcs/libVCSMarple.a( vcs.o): In
    function `std::map<char const*, int, std::less<char const*>,
    std::allocator< std::pair<char const* const, int> > >::map()':
    vcs.o(.gnu.link once.t._ZNSt3ma pIPKciSt4lessIS 1_ESaISt4pairIK S1_iEEEC1Ev+0x4 c
    ): undefined reference to `_Unwind_Resume '
    ....

    I have tried compiling the final binary (which uses both C and C++ compiled
    objects) with "-lstdc++". That fixes these issues on gcc 3.1, but causes
    the above problems with the 2.96. Perhaps another library needs to be added
    to the link line?

    Thanks!
    Scott

    --
    Remove ".nospam" from the user ID in my e-mail to reply via e-mail.


  • Rolf Magnus

    #2
    Re: Unresolved Symbols from C++ Code

    Scott Brady Drummonds wrote:
    [color=blue]
    > Hi, everyone,
    >
    > I'm writing a bunch of C++ code that is going to be linked into a
    > program compiled with gcc (version 2.96; I have no option of changing
    > this version). My C++ code compiles and executes without error in my
    > C++ test harness. However, things fail once I move to gcc.
    >
    > Specifically, I'm getting errors like the following:
    >
    > vcs.o(.text+0xf ): undefined reference to `operator new(unsigned)'
    > vcs.o(.text+0x4 9): undefined reference to `operator delete(void*)'
    > vcs.o(.text+0x5 a): undefined reference to `_Unwind_Resume '
    > vcs.o(.text+0x6 b): undefined reference to `operator delete(void*)'
    > vcs.o(.text+0xa 9): undefined reference to `_Unwind_Resume '
    > vcs.o(.text+0x1 49): undefined reference to
    > `std::allocator <char>::allocat or()'
    > vcs.o(.text+0x1 5f): undefined reference to `std::string::s tring(char
    > const*, std::allocator< char> const&)'
    > vcs.o(.text+0x1 89): undefined reference to `std::string::~ string()'
    > vcs.o(.text+0x1 99): undefined reference to `std::string::~ string()'
    > vcs.o(.text+0x1 ac): undefined reference to
    > `std::allocator <char>::~alloca tor()'
    > vcs.o(.text+0x1 bc): undefined reference to
    > `std::allocator <char>::~alloca tor()'
    > ...
    > /usr/users/home4/sdrummon/src/marple/src/vcs/libVCSMarple.a( vcs.o): In
    > function `std::map<char const*, int, std::less<char const*>,
    > std::allocator< std::pair<char const* const, int> > >::map()':
    >[/color]
    vcs.o(.gnu.link once.t._ZNSt3ma pIPKciSt4lessIS 1_ESaISt4pairIK S1_iEEEC1E
    +0x4c[color=blue]
    > ): undefined reference to `_Unwind_Resume '
    > ...
    >
    > I have tried compiling the final binary (which uses both C and C++
    > compiled objects) with "-lstdc++".[/color]

    You mean s/compiling/linking/. Looks to me as if you're linking with gcc
    instead of g++.
    [color=blue]
    > That fixes these issues on gcc 3.1, but causes the above problems with[/color]
    the 2.96. Perhaps another library needs to be added to the link line?

    Maybe. Just use g++ for linking. This will automatically added
    everything that's needed.

    Comment

    • Scott Brady Drummonds

      #3
      Re: Unresolved Symbols from C++ Code

      Well, after several hours of trial-and-error, I seem to have fixed this
      problem. I was compiling the C++ source with g++ 3.1 and that was getting
      linked to the C source using gcc 2.96. Early experiments suggest that
      backing the C++ compiler back to 2.96 fix the problem.

      I know it's academic at this point, but I'd like to know why the version
      imcompatibility caused the unresolved symbols mentioned below. Can someone
      explain?

      Scott

      "Scott Brady Drummonds" <scott.b.drummo nds.nospam@inte l.com> wrote in
      message news:bm1ps6$omj $1@news01.intel .com...[color=blue]
      > Hi, everyone,
      >
      > I'm writing a bunch of C++ code that is going to be linked into a program
      > compiled with gcc (version 2.96; I have no option of changing this[/color]
      version).[color=blue]
      > My C++ code compiles and executes without error in my C++ test harness.
      > However, things fail once I move to gcc.
      >
      > Specifically, I'm getting errors like the following:
      >
      > vcs.o(.text+0xf ): undefined reference to `operator new(unsigned)'
      > vcs.o(.text+0x4 9): undefined reference to `operator delete(void*)'
      > vcs.o(.text+0x5 a): undefined reference to `_Unwind_Resume '
      > vcs.o(.text+0x6 b): undefined reference to `operator delete(void*)'
      > vcs.o(.text+0xa 9): undefined reference to `_Unwind_Resume '
      > vcs.o(.text+0x1 49): undefined reference to
      > `std::allocator <char>::allocat or()'
      > vcs.o(.text+0x1 5f): undefined reference to `std::string::s tring(char[/color]
      const*,[color=blue]
      > std::allocator< char> const&)'
      > vcs.o(.text+0x1 89): undefined reference to `std::string::~ string()'
      > vcs.o(.text+0x1 99): undefined reference to `std::string::~ string()'
      > vcs.o(.text+0x1 ac): undefined reference to
      > `std::allocator <char>::~alloca tor()'
      > vcs.o(.text+0x1 bc): undefined reference to
      > `std::allocator <char>::~alloca tor()'
      > ...
      > /usr/users/home4/sdrummon/src/marple/src/vcs/libVCSMarple.a( vcs.o): In
      > function `std::map<char const*, int, std::less<char const*>,
      > std::allocator< std::pair<char const* const, int> > >::map()':
      >[/color]
      vcs.o(.gnu.link once.t._ZNSt3ma pIPKciSt4lessIS 1_ESaISt4pairIK S1_iEEEC1Ev+0x4 c[color=blue]
      > ): undefined reference to `_Unwind_Resume '
      > ...
      >
      > I have tried compiling the final binary (which uses both C and C++[/color]
      compiled[color=blue]
      > objects) with "-lstdc++". That fixes these issues on gcc 3.1, but causes
      > the above problems with the 2.96. Perhaps another library needs to be[/color]
      added[color=blue]
      > to the link line?
      >
      > Thanks!
      > Scott
      >
      > --
      > Remove ".nospam" from the user ID in my e-mail to reply via e-mail.
      >
      >[/color]


      Comment

      • Jonathan Mcdougall

        #4
        Re: Unresolved Symbols from C++ Code

        > > I'm writing a bunch of C++ code that is going to be linked into a
        program[color=blue][color=green]
        > > compiled with gcc (version 2.96; I have no option of changing this[/color]
        > version).[/color]

        <snip>

        First, do not top-post. Second, do not include the whole message if you
        are only answering to parts of it (what's more, it was _your_ message).
        [color=blue]
        > I know it's academic at this point, but I'd like to know why the version
        > imcompatibility caused the unresolved symbols mentioned below. Can[/color]
        someone[color=blue]
        > explain?[/color]

        No, please post to the approriate forum.




        Jonathan


        Comment

        Working...