Rules | Recent posts | topic RSS | Search | Register  | Log in

Need help to compile the file in C++ in linux

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> Linux Software
Author Message
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post05 May 2008 12:27   Need help to compile the file in C++ in linux

Hello all,

i am learning C++ on linux.
i have tried to compile very simple code "Fiert.cc"

Code:
1: #include <iostream.h>
2:
3: main()
4: {
5:     float pi = 3.14;
6:     cout << "The value of pi is " << pi << "\n";
7:     return 0;

8: }

when i compiled this code i am getting such warning msg.

Quote:
In file included from /usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
from 1.cpp:1:
/usr/lib/gcc/i386-redhat-linux/4.1.2/../../../../include/c++/4.1.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/ccYMN8qn.o: In function `__static_initialization_and_destruction_0(int, int)':
1.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/ccYMN8qn.o: In function `__tcf_0':
1.cpp:(.text+0x6c): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccYMN8qn.o: In function `main':
1.cpp:(.text+0x96): undefined reference to `std::cout'
1.cpp:(.text+0x9b): 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*)'
1.cpp:(.text+0xac): undefined reference to `std::basic_ostream<char, std::char_traits<char> >::operator<<(float)'
1.cpp:(.text+0xbc): 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/ccYMN8qn.o: (.eh_frame+0x11): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status


can any one please help me to solve this problem..??
Back to top
aospinas



Joined: 24 Nov 2003
Posts: 34
Helped: 6


Post05 May 2008 17:03   Re: Need help to compile the file in C++ in linux

Hi

Everything in standard headers like <iostream> is inside std namespace, hence
it's std::cin and std::cout .
btw, cin and cout are not functions.

change iostream.h by.. iostream

Code:

#include <iostream>
main()
{
float pi = 3.14;
std::cout << "The value of pi is " << pi << "\n";
return 0;
}



compile:
$ g++ Fiert.cc -o Fiert.out


g++ compile c++
gcc compile c

enjoy
Back to top
H_D_R



Joined: 31 Jan 2008
Posts: 361
Helped: 17
Location: India


Post06 May 2008 4:47   Re: Need help to compile the file in C++ in linux

Thank you so much aospinas,

i have got the solution.
BTW, i was able to see output from my code also but the problem was warning. it was appearing on every compilation.

anyway thanks a lot again...!!!

--- bless you..Very Happy Very Happy
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> Linux Software
Page 1 of 1 All times are GMT + 2 Hours


Abuse
Administrator
Moderators
topic RSS 
sitemap