N00b looking for GCC error help.

Discussion in 'C++' started by sublimanized@gmail.com, Feb 28, 2007.

  1. Guest

    Hello all ... here is my problem. I just got the book "Teach Yourself C
    ++ in 21 Days"

    Setup:
    Fedora Core 6 - i386
    GCC 4.1.1

    Again, I am a complete newcomer to C++, and this is one of the first
    examples out of the book. I want to know why exactly this doesn't
    clean compile, and how would i fix it?


    #####################################################################
    #include <iostream>

    int Add (int x, int y)
    {
    std::cout << "In Add(), recieved " << x << " and " << y << "\n";
    return (x+y);
    }

    int main()
    {
    using std::cout;
    using std::cin;

    cout << "I'm in main()!\n";
    int a, b, c;

    cout << "Enter two nunber: ";
    cin >> a;
    cin >> b;

    cout << "\nCalling Add()\n";
    c=Add(a,b);
    cout << "\nBack in main().\n";
    cout << "c was set to " << c;
    cout << "\nExiting ... \n\n";

    return 0;
    }
    ###########################################################




    $ gcc ./Func.cpp -o Func

    /tmp/cc3B71PJ.o: In function
    `__static_initialization_and_destruction_0(int, int)':
    Func.cpp:(.text+0x23): undefined reference to
    `std::ios_base::Init::Init()'
    /tmp/cc3B71PJ.o: In function `__tcf_0':
    Func.cpp:(.text+0x6c): undefined reference to
    `std::ios_base::Init::~Init()'
    /tmp/cc3B71PJ.o: In function `Add(int, int)':
    Func.cpp:(.text+0x83): undefined reference to `std::cout'
    Func.cpp:(.text+0x88): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0x99): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
    Func.cpp:(.text+0xa9): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0xba): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
    Func.cpp:(.text+0xca): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    /tmp/cc3B71PJ.o: In function `main':
    Func.cpp:(.text+0xf2): undefined reference to `std::cout'
    Func.cpp:(.text+0xf7): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0x106): undefined reference to `std::cout'
    Func.cpp:(.text+0x10b): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0x119): undefined reference to `std::cin'
    Func.cpp:(.text+0x11e): undefined reference to
    `std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
    Func.cpp:(.text+0x12c): undefined reference to `std::cin'
    Func.cpp:(.text+0x131): undefined reference to
    `std::basic_istream<char, std::char_traits<char> >::eek:perator>>(int&)'
    Func.cpp:(.text+0x140): undefined reference to `std::cout'
    Func.cpp:(.text+0x145): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0x169): undefined reference to `std::cout'
    Func.cpp:(.text+0x16e): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0x17d): undefined reference to `std::cout'
    Func.cpp:(.text+0x182): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    Func.cpp:(.text+0x193): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >::eek:perator<<(int)'
    Func.cpp:(.text+0x1a2): undefined reference to `std::cout'
    Func.cpp:(.text+0x1a7): undefined reference to
    `std::basic_ostream<char, std::char_traits<char> >& std::eek:perator<<
    <std::char_traits<char> >(std::basic_ostream<char,
    std::char_traits<char> >&, char const*)'
    /tmp/cc3B71PJ.o:(.eh_frame+0x11): undefined reference to
    `__gxx_personality_v0'
    collect2: ld returned 1 exit status
     
    , Feb 28, 2007
    #1
    1. Advertising

  2. Ian Collins Guest

    wrote:
    >
    > Again, I am a complete newcomer to C++, and this is one of the first
    > examples out of the book. I want to know why exactly this doesn't
    > clean compile, and how would i fix it?
    >
    >
    > $ gcc ./Func.cpp -o Func
    >

    g++ ./Func.cpp -o Func

    --
    Ian Collins.
     
    Ian Collins, Feb 28, 2007
    #2
    1. Advertising

  3. On 28 fev, 17:02, wrote:
    > Hello all ... here is my problem. I just got the book "Teach Yourself C
    > ++ in 21 Days"

    [snip]

    You should be using "Accelerated C++" or "You Can Do It" to start in C+
    +.

    >
    > Setup:
    > Fedora Core 6 - i386
    > GCC 4.1.1
    >
    > Again, I am a complete newcomer to C++, and this is one of the first
    > examples out of the book. I want to know why exactly this doesn't
    > clean compile, and how would i fix it?
    >
    >

    [snip]
    > $ gcc ./Func.cpp -o Func


    This is off-topic here, but try:

    $ g++ ./Func.cpp -o Func

    The problem seems you didn't link the STL code.

    HTH,

    Marcelo Pinto
     
    Marcelo Pinto, Feb 28, 2007
    #3
  4. wrote:
    > Hello all ... here is my problem. I just got the book "Teach Yourself
    > C ++ in 21 Days"
    >
    > Setup:
    > Fedora Core 6 - i386
    > GCC 4.1.1
    >
    > Again, I am a complete newcomer to C++, and this is one of the first
    > examples out of the book. I want to know why exactly this doesn't
    > clean compile, and how would i fix it?
    >
    >
    > #####################################################################

    [..]
    > ###########################################################
    >
    >
    >
    >
    > $ gcc ./Func.cpp -o Func
    >
    > /tmp/cc3B71PJ.o: In function
    > `__static_initialization_and_destruction_0(int, int)':
    > Func.cpp:(.text+0x23): undefined reference to
    > `std::ios_base::Init::Init()'

    [..]
    > collect2: ld returned 1 exit status


    Whenever you have linker errors ('ld' is the linker), you need to
    make sure you're supplying all the necessary modules to it. How?
    That's an implementation-specific question. Try gnu.g++.help NG.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Feb 28, 2007
    #4
  5. Guest

    Wow .... i feel like an idiot.

    "g++" did the trick.

    Thanks for the help, everybody.
     
    , Feb 28, 2007
    #5
    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. Replies:
    8
    Views:
    464
  2. Kevin P. Fleming

    C99 structure initialization in gcc-2.95.3 vs gcc-3.3.1

    Kevin P. Fleming, Nov 6, 2003, in forum: C Programming
    Replies:
    2
    Views:
    680
    Kevin P. Fleming
    Nov 6, 2003
  3. Replies:
    5
    Views:
    390
    Nathan Addy
    Sep 17, 2005
  4. ashnin

    GCC 3.4.3 and GCC 4.1.2

    ashnin, Jul 7, 2008, in forum: C++
    Replies:
    1
    Views:
    588
    Michael DOUBEZ
    Jul 7, 2008
  5. na
    Replies:
    4
    Views:
    202
Loading...

Share This Page