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 01-29-2006, 07:45 AM   #1
bogoda
Member
 
Registered: Jan 2006
Posts: 32
Blog Entries: 2

Rep: Reputation: 15
Question Compile error on c++


I am using RH9.

I tried to compile simple program and save it as Teat.cpp

#include<iostream.h>

int main()
{
cout << "Hello Cplusplus";
return 0;
}



using the command cc -o te Test.cpp i compile it.

It gives an error as follows.


In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from Test.cpp:1:
/usr/include/c++/3.2.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <sstream> instead of the deprecated header <strstream.h>. To disable this warning use -Wno-deprecated.
/tmp/ccrOBvuR.o(.text+0x19): In function `main':
: undefined reference to `std::cout'
/tmp/ccrOBvuR.o(.text+0x1e): 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/ccrOBvuR.o(.text+0x4a): In function `__static_initialization_and_destruction_0(int, int)':
: undefined reference to `std::ios_base::Init::Init[in-charge]()'
/tmp/ccrOBvuR.o(.text+0x79): In function `__tcf_0':
: undefined reference to `std::ios_base::Init::~Init [in-charge]()'
/tmp/ccrOBvuR.o(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
 
Old 01-29-2006, 08:09 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
The warnings tell you to use (for example) "#include <iostream>". With this, you will also need to have a line saying "using namespace std;" (or "using std::cout;").

You should probably be using g++ to compile C++ programs, as cc as you're using it is for compiling C programs. On my system, cc is a symlink to gcc and it might be the same on yours. There might be an option to use with gcc to compile C++ programs, but I'm not sure. Just use g++.

Also, why on Earth are you using Red Hat 9?!
 
Old 01-30-2006, 09:59 AM   #3
bogoda
Member
 
Registered: Jan 2006
Posts: 32

Original Poster
Blog Entries: 2

Rep: Reputation: 15
I don the changes but it does not work.

Whats the wrong.

It works well for printf function
Any one knows
 
Old 01-30-2006, 10:03 AM   #4
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
What is the command you're using to compile?
 
Old 01-30-2006, 11:56 AM   #5
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Hi,

Take this code and save it as test.cpp

Code:
#include<iostream>

int main()
{
	std::cout << "Hello Cplusplus" << std::endl;
	return 0;
}
now issue the following commands

Code:
$ g++ -o test test.cpp
$ ./test
Hello Cplusplus
$
I have just tested this process and it works on my system (Fedora 4) so if your system is set up correctly it should work.

graeme.
 
  


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
Compile Error Renegade498 Linux - General 3 03-24-2005 07:50 PM
Error after compile to 2.6.7 Reefcrazed Slackware 22 08-13-2004 08:59 PM
compile error dementia1 Linux - Software 11 07-27-2004 12:19 PM
compile error: #error unknown processor family kmack2001 Linux - Newbie 0 02-14-2004 11:52 AM
Alsa compile error, and a WINE error scheidel21 Linux - Software 1 12-08-2003 08:16 PM

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

All times are GMT -5. The time now is 12:51 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