Can't compile HW

V

vcgeek

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(.text+0x14): In function `main':
: undefined reference to `std::basic_ostream<char,
std::char_traits said:
(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccIWkyfm.o(.text+0x21): In function `main':
: undefined reference to `std::cout'
/tmp/ccIWkyfm.o(.text+0x26): In function `main':
: undefined reference to `std::basic_ostream<char,
std::char_traits said:
(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccIWkyfm.o(.text+0x2f): In function `main':
: undefined reference to `std::basic_ostream<char,
std::char_traits<char> >::eek:perator<<(std::basic_ostream<char,
std::char_traits<char> >& (*)(std::basic_ostream<char,
std::char_traits<char> >&))'
/tmp/ccIWkyfm.o(.text+0x5c): In function
`__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccIWkyfm.o(.text+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_personality_v0'
collect2: ld returned 1 exit status

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

Victor Bazarov

vcgeek said:
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
 
V

vcgeek

Victor said:
vcgeek said:
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
 
F

Frederick Gotham

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

Default User

vcgeek said:
Victor said:
vcgeek said:
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)
 
J

Jerry Coffin

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,060
Latest member
BuyKetozenseACV

Latest Threads

Top