LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 09-14-2004, 02:05 PM   #1
harmster
LQ Newbie
 
Registered: Feb 2004
Posts: 25

Rep: Reputation: 15
Question cpp hello world not working


Hi all,

The strangest thing happen today. I was trying on some cpp after years of java programming and some c programming. First you make the (in)famous 'Hello World' program. But I can't seem to get it right. I think the code is okay but there is something missing in, I suspect, the global variables for my gcc(version 3.3.4 (Debian 1:3.3.4-11)). Can some one please explain this or me?
The code is as follows:
Code:
#include <iostream>
using namespace std;

int main()
{
    cout << "hello world";
    return 0;
}
The error I get when compiling:
Code:
harm@castle:~/prj/cpp$ gcc hello.cpp 
/tmp/ccvGiPa0.o(.text+0x1b): In function `main':
: undefined reference to `std::cout'
/tmp/ccvGiPa0.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/ccvGiPa0.o(.text+0x49): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccvGiPa0.o(.text+0x7a): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccvGiPa0.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
harm@castle:~/prj/cpp$
This junk utterly mystifies me. Please help me.

With kind regards,
Harm
 
Old 09-14-2004, 02:13 PM   #2
N43
LQ Newbie
 
Registered: Sep 2004
Location: Germany
Distribution: Slackware
Posts: 13

Rep: Reputation: 0
use g++ instead of gcc: g++ hello.cpp -o hello
 
Old 09-14-2004, 02:17 PM   #3
Mega Man X
LQ Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 65
You have a cpp program and you are trying to compile with "gcc". You've to compile it with "g++". Syntax:

g++ -o executable hello.cpp

It will create an executable called "executable" that you run with "./executableöe". If it was a c program (say hello.c) then:

gcc -o executable hello.c

It's also common to save c++ files as either ".cpp" or ".cc". Also, I don't think gcc/++ compiles a file by simply typing "g++ filename.cpp" as it did before. You've to specify the executable name. It did on the good old times though...

But as always, I could be wrong
 
Old 09-14-2004, 02:21 PM   #4
harmster
LQ Newbie
 
Registered: Feb 2004
Posts: 25

Original Poster
Rep: Reputation: 15
g++ works! Great! But the manual pages direct me to gcc with 'man g++' so I assumed gcc and g++ where the same thing. But apparently not. Thanks for your quick replies!
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ethernet card not working in FC3.. Anybody in the world Who can help me out .. ozzie_penguin Linux - Hardware 1 08-17-2005 04:12 AM
Gentoo: emerge -uUa world is no longer working PGDubbin Linux - Distributions 5 10-08-2004 01:49 PM
debian dpkg cpp depends on cpp error darkleaf Linux - Software 2 06-25-2004 01:47 AM
world writeable files will not stay world writeable antken Mandriva 1 03-02-2004 05:04 PM
Now I have gcc/cpp/cpp, but still can't install sfingerh Linux - Software 2 07-30-2002 03:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:08 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration