C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old May 8th, 2008, 11:11 PM
siypke siypke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 siypke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 19 sec
Reputation Power: 0
Simple compiling problem

hallo all...

this is my first time in programming...
i wrote this simple C++ code :

Code:
#include <iostream.h>
void main()
    {
	cout << "hello, World!" << endl;
    }


is use GCC as a compiler...but when compile this code,,the error appear..like this..

Code:
In file included from /usr/include/c++/4.1.3/backward/iostream.h:31,
                 from hello.cpp:1:
/usr/include/c++/4.1.3/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 <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
hello.cpp:2: error: ‘::main’ must return ‘int’


what should i do???

thanks before!!!

Reply With Quote
  #2  
Old May 8th, 2008, 11:23 PM
spoon! spoon! is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2006
Posts: 247 spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level)spoon! User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 8 h 15 m 23 sec
Reputation Power: 77
so first of all, <iostream.h> is not a standard header. <iostream> is the header you should use, and all the things in that header are in the std namespace

second, the main() function must return an int

Code:
#include <iostream>
int main()
    {
	std::cout << "hello, World!" << std::endl;
	return 0;
    }

Reply With Quote
  #3  
Old May 8th, 2008, 11:33 PM
siypke siypke is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 2 siypke User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 14 m 19 sec
Reputation Power: 0
but,,when iam compile again this thing appear

Code:
/tmp/ccuZYfej.o: In function `__static_initialization_and_destruction_0(int, int)':
hello.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccuZYfej.o: In function `__tcf_0':
hello.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccuZYfej.o: In function `main':
hello.cpp:(.text+0x8e): undefined reference to `std::cout'
hello.cpp:(.text+0x93): 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*)'
hello.cpp:(.text+0x9b): 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> >&)'
hello.cpp:(.text+0xa3): 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/ccuZYfej.o:(.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


is there a problem with the GCC??

thanks before!!

Reply With Quote
  #4  
Old May 9th, 2008, 02:10 AM
etienne141's Avatar
etienne141 etienne141 is offline
Paris est magique!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Location: France!
Posts: 346 etienne141 User rank is Sergeant Major (2000 - 5000 Reputation Level)etienne141 User rank is Sergeant Major (2000 - 5000 Reputation Level)etienne141 User rank is Sergeant Major (2000 - 5000 Reputation Level)etienne141 User rank is Sergeant Major (2000 - 5000 Reputation Level)etienne141 User rank is Sergeant Major (2000 - 5000 Reputation Level)etienne141 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 5 Days 2 h 12 m 41 sec
Reputation Power: 41
Send a message via ICQ to etienne141 Send a message via MSN to etienne141
Instead of calling gcc, try g++. Or rename your file to ***.cpp.
__________________
UNIX shells are so cool!
etienne:~ > %blow
fg: %blow: no such job


There are 10 kind of people:
- those who know binary
- those who don't.

Reply With Quote
  #5  
Old May 11th, 2008, 11:44 AM
Fuial Fuial is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2008
Posts: 6 Fuial New User: is a brand new recruit and a unknown entity at this point. 
Time spent in forums: 43 m 31 sec
Reputation Power: 0
The gcc is the compiler for c, you must use g++ for compiling a cpp file.
If it didnt work, please post the command line you are executing for compiling.

Reply With Quote
  #6  
Old May 11th, 2008, 12:01 PM
clifford's Avatar
clifford clifford is online now
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2003
Location: UK
Posts: 2,413 clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level)clifford User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 6 h 28 m 42 sec
Reputation Power: 320
Quote:
Originally Posted by Fuial
The gcc is the compiler for c, you must use g++ for compiling a cpp file.
Not entirely true, gcc will compile C++ code, but if you use it to invoke the linker, it will not implicitly link the C++ standard library as a default library. They are both in fact the same compiler wrapper, but with different defaults.

Reply With Quote
  #7  
Old May 11th, 2008, 05:19 PM
sizablegrin's Avatar
sizablegrin sizablegrin is offline
Stubborn ol' L'User
Click here for more information.
 
Join Date: Jun 2005
Posts: 3,070 sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level)sizablegrin User rank is General 7th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 1 Day 16 h 7 m 21 sec
Reputation Power: 1446
In addition to the other germane comments, it seems strange to me that an error message like
Quote:
hello.cpp:2: error: ‘::main’ must return ‘int’

seems obscure to you, particularly when you have asked main to return a void.

Some error messages are, indeed, rather obscure for the uninitiated. Still, you wouldn't want the error message to say, "Don't declare main to return void, dummy, declare it to return int!!!!11111eleven." Would you? Of course, you can't just declare it like that. You have to follow through and actually return an int, unless your compiler spoils you like your mama, and generates the statement for you.
__________________
C/C++ pointers (Original in the "Commonly Asked Questions" thread).

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > Simple compiling problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway