compile problem

G

Gen

I write a simple problem ,as:

******************************
//temp.cpp
#include<iostream.h>

int main(void){
cout<<"123131231";
return 0;
}

*****************************

and when I type "gcc -o temp temp.cpp", it shows:

*******************************
In file included from /usr/include/c++/4.0.2/backward/iostream.h:31,
from temp.cpp:1:
/usr/include/c++/4.0.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 <iostream> instead of
the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/tmp/cc2wKN3t.o: In function `main':
temp.cpp:(.text+0x25): undefined reference to `std::cout'
temp.cpp:(.text+0x2a): undefined reference to `std::basic_ostream<char,
std::char_traits said:
(std::basic_ostream<char, std::char_traits<char> >&, char const*)'

/tmp/cc2wKN3t.o: In function `__tcf_0':
temp.cpp:(.text+0x47): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/cc2wKN3t.o: In function
`__static_initialization_and_destruction_0(int, int)':
temp.cpp:(.text+0x74): undefined reference to
`std::ios_base::Init::Init()'
/tmp/cc2wKN3t.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

*******************************

Could anyone tell me what teh problem is?
 
V

Victor Bazarov

Gen said:
I write a simple problem ,as:

******************************
//temp.cpp
#include<iostream.h>

int main(void){
cout<<"123131231";
return 0;
}

*****************************

and when I type "gcc -o temp temp.cpp", it shows:

[..]

Could anyone tell me what teh problem is?

The problem mostly is that this code is approximately 10 years behind
the language. C++ does not have <iostream.h> as of 1998. And actually
it was taken out even earlier than that, at least I don't recall it at
the time the second draft was published, 1996, was it?

To make this code a C++ program you need to change it to

//temp.cpp
#include<iostream>

int main(void){
std::cout<<"123131231";
return 0;
}

Of course, 'void' is unnecessary (and better avoided, pun intended) and
'return 0' is also implicit if omitted. So, you could simply write

#include <iostream>

int main() {
std::cout << "123131231";
}

Get yourself a decent book, better published after 2000.

V
 
O

osmium

:
/tmp/cc2wKN3t.o: In function `main':
temp.cpp:(.text+0x25): undefined reference to `std::cout'
temp.cpp:(.text+0x2a): undefined reference to `std::basic_ostream<char,


/tmp/cc2wKN3t.o: In function `__tcf_0':
temp.cpp:(.text+0x47): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/cc2wKN3t.o: In function
`__static_initialization_and_destruction_0(int, int)':
temp.cpp:(.text+0x74): undefined reference to
`std::ios_base::Init::Init()'
/tmp/cc2wKN3t.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

All that blather is telling you that you don't know about namespaces.
 
A

Artie Gold

osmium said:
:



All that blather is telling you that you don't know about namespaces.
Erm, actually not. It doesn't say that at all.
What it *does* say is that the OP has not invoked the compilation system
in the correct way. Alas, such things being off topic, I cannot
elaborate further.

<OT>
RTFM!!!
</OT>

HTH,
--ag
 
H

HappyHippy

Gen said:
I write a simple problem ,as:

******************************
//temp.cpp
#include<iostream.h>

int main(void){
cout<<"123131231";
return 0;
}

*****************************

and when I type "gcc -o temp temp.cpp", it shows:

*******************************
In file included from /usr/include/c++/4.0.2/backward/iostream.h:31,
from temp.cpp:1:
/usr/include/c++/4.0.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 <iostream> instead of
the deprecated header <iostream.h>. To disable this warning use
-Wno-deprecated.
/tmp/cc2wKN3t.o: In function `main':
temp.cpp:(.text+0x25): undefined reference to `std::cout'
temp.cpp:(.text+0x2a): undefined reference to `std::basic_ostream<char,


/tmp/cc2wKN3t.o: In function `__tcf_0':
temp.cpp:(.text+0x47): undefined reference to
`std::ios_base::Init::~Init()'
/tmp/cc2wKN3t.o: In function
`__static_initialization_and_destruction_0(int, int)':
temp.cpp:(.text+0x74): undefined reference to
`std::ios_base::Init::Init()'
/tmp/cc2wKN3t.o:(.eh_frame+0x11): undefined reference to
`__gxx_personality_v0'
collect2: ld returned 1 exit status

*******************************

Could anyone tell me what teh problem is?
try g++ instead of gcc:

"g++ -o temp temp.cpp"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top