Can't compile HW

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • vcgeek

    #1

    Can't compile HW

    I'm just beginning and I'm having trouble starting. Can't get this to
    compile and could use some direction.

    #include <iostream>
    using namespace std;

    int main () {
    cout << "Hello World" << endl;
    }

    Here are the particulars:
    uname -a
    Linux tegary-lnx 2.4.20-8 #1 Thu Mar 13 17:54:28 EST 2003 i686 i686
    i386 GNU/Linux

    gcc --version
    gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
    Copyright (C) 2002 Free Software Foundation, Inc.
    This is free software; see the source for copying conditions. There is
    NO
    warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
    PURPOSE.

    gcc hw.cc
    /tmp/ccIWkyfm.o(.tex t+0x14): In function `main':
    : undefined reference to `std::basic_ost ream<char,
    std::char_trait s<char& std::endl<char, std::char_trait s<char>
    >(std::basic_os tream<char, std::char_trait s<char&)'
    /tmp/ccIWkyfm.o(.tex t+0x21): In function `main':
    : undefined reference to `std::cout'
    /tmp/ccIWkyfm.o(.tex t+0x26): In function `main':
    : undefined reference to `std::basic_ost ream<char,
    std::char_trait s<char& std::operator<< <std::char_trai ts<char>
    >(std::basic_os tream<char, std::char_trait s<char&, char const*)'
    /tmp/ccIWkyfm.o(.tex t+0x2f): In function `main':
    : undefined reference to `std::basic_ost ream<char,
    std::char_trait s<char::operato r<<(std::basic_ ostream<char,
    std::char_trait s<char& (*)(std::basic_ ostream<char,
    std::char_trait s<char&))'
    /tmp/ccIWkyfm.o(.tex t+0x5c): In function
    `__static_initi alization_and_d estruction_0(in t, int)':
    : undefined reference to `std::ios_base: :Init::Init[in-charge]()'
    /tmp/ccIWkyfm.o(.tex t+0x8b): In function `__tcf_0':
    : undefined reference to `std::ios_base: :Init::~Init [in-charge]()'
    /tmp/ccIWkyfm.o(.eh_ frame+0x11): undefined reference to
    `__gxx_personal ity_v0'
    collect2: ld returned 1 exit status

    Didn't think I'd need help this early.
    TIA
    Gary

  • Victor Bazarov

    #2
    Re: Can't compile HW

    "vcgeek" <vcgeek@gmail.c omwrote...
    I'm just beginning and I'm having trouble starting. Can't get this to
    compile and could use some direction.
    >
    [...]
    gcc hw.cc
    [..]
    Don't use gcc, use g++. Next time you have a problem using gcc or g++
    please post to 'gnu.gcc.help' or 'gnu.g++.help'.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask


    Comment

    • vcgeek

      #3
      Re: Can't compile HW


      Victor Bazarov wrote:
      "vcgeek" <vcgeek@gmail.c omwrote...
      I'm just beginning and I'm having trouble starting. Can't get this to
      compile and could use some direction.

      [...]
      gcc hw.cc
      [..]
      >
      Don't use gcc, use g++. Next time you have a problem using gcc or g++
      please post to 'gnu.gcc.help' or 'gnu.g++.help'.
      >
      Thanks for g++ that appears to work. I had tried it earlier but must
      have had some other problem. The doc sounds like either should work.

      Also thanks for the correct group with out the flames.

      Gary

      V
      --
      Please remove capital 'A's when replying by e-mail
      I do not respond to top-posted replies, please don't ask

      Comment

      • Frederick Gotham

        #4
        Re: Can't compile HW

        vcgeek posted:
        I'm just beginning and I'm having trouble starting. Can't get this to
        compile and could use some direction.
        >
        #include <iostream>
        using namespace std;
        >
        int main () {
        cout << "Hello World" << endl;
        }

        First, I'd recommend changing that to:

        #include <ostream>
        #include <iostream>

        using std::cout;
        using std::endl;

        int main()
        {
        cout << "Hello World" << endl;
        }

        gcc hw.cc

        You're using the C compiler, not the C++ compiler.

        Have you tried Dev-C++? I use it and it's pretty handy.

        --

        Frederick Gotham

        Comment

        • Default User

          #5
          Re: Can't compile HW

          vcgeek wrote:
          >
          Victor Bazarov wrote:
          "vcgeek" <vcgeek@gmail.c omwrote...
          I'm just beginning and I'm having trouble starting. Can't get
          this to compile and could use some direction.
          >
          [...]
          gcc hw.cc
          [..]
          Don't use gcc, use g++. Next time you have a problem using gcc or
          g++ please post to 'gnu.gcc.help' or 'gnu.g++.help'.
          >
          Thanks for g++ that appears to work. I had tried it earlier but must
          have had some other problem. The doc sounds like either should work.
          Either will compile the code. What g++ does for you is link the proper
          libraries.




          Brian (thinks it seems needlessly tricky)

          Comment

          • Jerry Coffin

            #6
            Re: Can't compile HW

            In article <1156528250.595 592.103160@m73g 2000cwd.googleg roups.com>,
            vcgeek@gmail.co m says...

            [ ... compiling C++ with: ]
            gcc hw.cc
            Try using "g++" instead of "gcc" and see it if doesn't help. Otherwise,
            you're probably better off asking somewhere related to gcc rather than
            C++. Here we discuss the language itself, not things like how to install
            and use compilers (I know it sounds picky, but keep in mind that even
            with the restricted range of topics, the volume here is already quite
            high).

            --
            Later,
            Jerry.

            The universe is a figment of its own imagination.

            Comment

            Working...