LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 08-26-2003, 03:39 PM   #1
mandrakeroot
LQ Newbie
 
Registered: Jul 2003
Distribution: Gentoo 1.4
Posts: 6

Rep: Reputation: 0
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.
 
Old 08-26-2003, 03:45 PM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
#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++.
 
Old 08-26-2003, 03:58 PM   #3
mandrakeroot
LQ Newbie
 
Registered: Jul 2003
Distribution: Gentoo 1.4
Posts: 6

Original Poster
Rep: Reputation: 0
I get this error:
<code>
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:perator<< <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> >:perator<<(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
<code>

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

int main()
{
cout <<"Hi"<< endl;
return 0;
}
<code>

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.
 
Old 08-26-2003, 04:18 PM   #4
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
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
 
Old 08-26-2003, 04:23 PM   #5
mandrakeroot
LQ Newbie
 
Registered: Jul 2003
Distribution: Gentoo 1.4
Posts: 6

Original Poster
Rep: Reputation: 0
I emerge applications all the time. wouldnt that mean that i have the right libs?
 
Old 08-26-2003, 04:30 PM   #6
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Um, how about using g++ instead of gcc since this is C++ and not C.
 
Old 08-26-2003, 04:42 PM   #7
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
g++ works for me, I wasn't thinking about that

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

Last edited by leonscape; 08-26-2003 at 04:47 PM.
 
Old 08-26-2003, 04:50 PM   #8
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
try changing your code like this, also for an editor try vim or emacs

Code:
#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
cout <<"Hi"<< endl;
return 0;
}
 
Old 08-26-2003, 05:06 PM   #9
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

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

Also vim and emacs are EVIL don't listen to him!
 
Old 08-26-2003, 05:24 PM   #10
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 50
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 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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write a simple c prog to call a script RajRed Programming 1 10-05-2005 05:10 PM
how to write a simple c prog to call a script RajRed Linux - Software 1 10-05-2005 02:57 PM
2 simple shell prog questions provkitir Linux - Software 3 11-23-2004 03:00 AM
Simple polygon area c++ prog. problems Hal Programming 4 08-28-2004 08:09 AM
Simple Perl prog. getting Error 500 message. XxAndyxX Programming 1 07-06-2003 11:25 AM


All times are GMT -5. The time now is 07:03 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration