|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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!!! ![]() |
|
#2
|
|||
|
|||
|
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;
}
|
|
#3
|
|||
|
|||
|
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!! ![]() |
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
||||
|
||||
|
Quote:
|
|
#7
|
||||
|
||||
|
In addition to the other germane comments, it seems strange to me that an error message like
Quote:
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). |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > Simple compiling problem |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|