-   Programming (
-   -   Something wrong with this simple hello world prog (

mandrakeroot 08-26-2003 04:39 PM

Something wrong with this simple hello world prog
#include <iostream.h>
#include <stdlib.h>

int main()
cout <<"hello world"<< endl;
return 0;

Whats wrong? It works in DOS at school but not at home. I have gcc compiler on gentoo.

leonscape 08-26-2003 04:45 PM

#include <iostream>
#include <iomanip>
using namespace std;

Your using C type includes with c++ code. and you missed out the namespace. you don't need stdlibs for this, also your using endl without iomanip.

MS and DOS rarely use proper ISO c++.

mandrakeroot 08-26-2003 04:58 PM

I get this error:
tux@localhost tux $ gcc alex.cpp
/tmp/ccjzKbHz.o(.text+0x1b): In function `main':
: undefined reference to `std::cout'
/tmp/ccjzKbHz.o(.text+0x20): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*)'
/tmp/ccjzKbHz.o(.text+0x28): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >& std::endl<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&)'
/tmp/ccjzKbHz.o(.text+0x30): In function `main':
: undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(std::basic_ostream<char, std::char_traits<char> >& (*)(std::basic_ostream<char, std::char_traits<char> >&))'
/tmp/ccjzKbHz.o(.text+0x59): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccjzKbHz.o(.text+0x8a): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccjzKbHz.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

with this code:
#include <iostream>
#include <iomanip>

int main()
cout <<"Hi"<< endl;
return 0;

I dont know what to do about it. My teacher only knows how to code it in turbo C++. also, I would like to know of an editor that does color coding for different parts of the C++ code.

leonscape 08-26-2003 05:18 PM

Try Anjunta for Gnome or Kdevelop for KDE. These are both IDE's for Linux.

Both do colour coding and set up makefiles and configure for you. also they do debugging.

gcc can't seem to find the standard libs. This maybe a result of installation problems.

Try installing libc6 and libc6-dev

mandrakeroot 08-26-2003 05:23 PM

I emerge applications all the time. wouldnt that mean that i have the right libs?

Strike 08-26-2003 05:30 PM

Um, how about using g++ instead of gcc since this is C++ and not C.

leonscape 08-26-2003 05:42 PM

g++ works for me, I wasn't thinking about that :)

Also the command should be
g++ contest.cpp -o contest

kev82 08-26-2003 05:50 PM

try changing your code like this, also for an editor try vim or emacs


#include <iostream>
#include <iomanip>

using namespace std;

int main()
cout <<"Hi"<< endl;
return 0;

leonscape 08-26-2003 06:06 PM

I didn't see He still missed that, (been up far to long :))

Also vim and emacs are EVIL don't listen to him! :D

kev82 08-26-2003 06:24 PM

its getting late, so now is not the time to start a vim/emacs/other war however if you can touch type i recommend vim if you cant i recommend emacs. leonscape is just confused :D hopefully in time he will learn.

i would like to comment on a few things
  • there are always loads of threads about kdevelop(and others) autogenerated makefiles not working, if you learn to write your own no problem.
  • vim and emacs have syntax highlighting for everything imaginable and more
  • there is nothing you can do in these awful ide's that you cant do in vim/emacs
  • vim/emacs run in the console so you can use them if you are connecting to another machine via ssh, or if your X isnt working
  • i can guarantee any unix machine you goto will have some sort of vi on it and most will have some sort of emacs, so wherever you are you have a text editor to hand
  • both vim and emacs are totally extensible
  • if this isnt enough i can come up with more reasons not to use a kdevelop style ide

All times are GMT -5. The time now is 06:48 AM.