HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT
2 posters
HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT
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
#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 : 35
Location : KOLKATA
Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT
to know whether gcc is installed or not, use this command
output
- 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.
Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT
also dont use gcc to compile c++ pgm. g++ is the C++ compiler. hope it works
- Code:
$ g++ sample.cpp
Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT
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
$ 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 : 35
Location : KOLKATA
Re: HOW TO COMPILE CPP PROGRAMS IN UNIX ENVIRONMENT
add this stmt before main function,
- Code:
using namespace std;
naga rishi- Posts : 8
Points : 3
Join date : 2010-03-08
Age : 35
Location : KOLKATA
Permissions in this forum:
You cannot reply to topics in this forum
|
|