HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Go down

HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by naga rishi on Tue Mar 09, 2010 4:35 pm

The following is a simple cpp program. could any one help me how to compile this.

#include<iostream.h>
int main()
{
cout<<"Hello World";
return 0;
}

I tried like this in shell. but it is showing lot of things that i cannot decipher

$ gcc hello.cpp


and the error it gave is -

In file included from /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/backward/iostream.h:31,
from hello.cpp:1:
/usr/lib/gcc/x86_64-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/cc1UUmIe.o: In function `__static_initialization_and_destruction_0(int, int)':
hello.cpp:(.text+0x23): undefined reference to `std::ios_base::Init::Init()'
/tmp/cc1UUmIe.o: In function `__tcf_0':
hello.cpp:(.text+0x66): undefined reference to `std::ios_base::Init::~Init()'
/tmp/cc1UUmIe.o: In function `main':
hello.cpp:(.text+0x76): undefined reference to `std::cout'
hello.cpp:(.text+0x7b): 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/cc1UUmIe.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status

naga rishi

Posts : 8
Points : 3
Join date : 2010-03-08
Age : 30
Location : KOLKATA

View user profile

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by Christopher on Tue Mar 09, 2010 8:50 pm

use "iostream" instead of "iostream.h"
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by Christopher on Tue Mar 09, 2010 8:56 pm

to know whether gcc is installed or not, use this command

Code:
$ gcc --version

output

Code:
gcc (Ubuntu 4.4.1-4ubuntu9) 4.4.1
Copyright (C) 2009 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by Christopher on Wed Mar 10, 2010 10:58 am

also dont use gcc to compile c++ pgm. g++ is the C++ compiler. hope it works Smile

Code:
$ g++ sample.cpp
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by naga rishi on Mon Mar 15, 2010 4:43 pm

I made the respective changes as you suggested. but still it is giving the following error.

$ g++ hello.cpp

hello.cpp: In function âint main()â:
hello.cpp:6: error: âcoutâ was not declared in this scope

naga rishi

Posts : 8
Points : 3
Join date : 2010-03-08
Age : 30
Location : KOLKATA

View user profile

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by Christopher on Mon Mar 15, 2010 4:49 pm

add this stmt before main function,
Code:
using namespace std;
Otherwise, instead of cout, use std::cout.
avatar
Christopher
Admin

Posts : 240
Points : 429
Join date : 2010-02-26
Age : 30

View user profile http://unixcpp.forumotion.com

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by naga rishi on Wed Mar 24, 2010 10:23 am

THANK YOU!

naga rishi

Posts : 8
Points : 3
Join date : 2010-03-08
Age : 30
Location : KOLKATA

View user profile

Back to top Go down

Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT

Post by Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum