Fedora Linux Support Community & Resources Center
  #1  
Old 16th April 2009, 03:58 PM
Anji_fedora Offline
Registered User
 
Join Date: Feb 2008
Location: India
Age: 24
Posts: 210
Unhappy ‘system’ was not declared in this scope

Here is my program

Quote:
#include<iostream>

using namespace std;

int main()
{
cout<<"Hello World\n";
system("pause");
return 0;

}
After running command "gcc pause.C" I get following error.

Quote:
pause.C: In function ‘int main()’:
pause.C:8: error: ‘system’ was not declared in this scope
After googling I found that i should add "#include<stdlib.h>
After adding that line I got even more error(given below). How can I solve this????

Quote:
/tmp/ccpeH8ni.o: In function `__static_initialization_and_destruction_0(int, int)':
pause.C: (.text+0x23): undefined reference to `std::ios_base::Init::Init()'
pause.C: (.text+0x28): undefined reference to `std::ios_base::Init::~Init()'
/tmp/ccpeH8ni.o: In function `main':
pause.C: (.text+0x5c): undefined reference to `std::cout'
pause.C: (.text+0x61): 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/ccpeH8ni.o: (.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
Reply With Quote
  #2  
Old 16th April 2009, 04:14 PM
mndar Offline
Registered User
 
Join Date: Feb 2005
Posts: 1,102
Try g++ pauce.C
__________________
GStreamer XOverlay and VideoOverlay http://mndar.phpnet.us/gstreamer
Reply With Quote
  #3  
Old 16th April 2009, 05:27 PM
Anji_fedora Offline
Registered User
 
Join Date: Feb 2008
Location: India
Age: 24
Posts: 210
Quote:
Originally Posted by mndar View Post
Try g++ pauce.C


Thanks it worked fine...... Anyway what is g++ command?



Also what is alternative for pause (below is output)???

Quote:
Hello World
sh: pause: command not found
Reply With Quote
  #4  
Old 17th April 2009, 12:06 AM
mndar Offline
Registered User
 
Join Date: Feb 2005
Posts: 1,102
Quote:
Thanks it worked fine...... Anyway what is g++ command?
g++ is the GNU C++ compiler
Quote:
Also what is alternative for pause (below is output)???
What exactly do u want to do?
__________________
GStreamer XOverlay and VideoOverlay http://mndar.phpnet.us/gstreamer
Reply With Quote
  #5  
Old 17th April 2009, 01:18 PM
Anji_fedora Offline
Registered User
 
Join Date: Feb 2008
Location: India
Age: 24
Posts: 210
Quote:
Originally Posted by mndar View Post
g++ is the GNU C++ compilerWhat exactly do u want to do?

Using pause I want to get effect of getch() (as in turbo C)


When I refer to man page of g++ it shows man page of gcc. Then what is difference between gcc and g++? Why g++ worked while gcc didn't (first tread)?
Reply With Quote
  #6  
Old 17th April 2009, 02:33 PM
markkuk Offline
Registered User
 
Join Date: Apr 2005
Location: Finland
Posts: 5,075
G++ links your code with the C++ standard library by default. The errors in message #1 are caused by the missing C++ library.
Reply With Quote
  #7  
Old 17th April 2009, 06:39 PM
sideways Offline
Retired User
 
Join Date: Oct 2004
Location: London, UK
Posts: 4,999
About the only place this is explained clearly is in the info manual for gcc

Code:
info gcc --index-search "g++"
Quote:
3.3 Compiling C++ Programs
==========================

C++ source files conventionally use one of the suffixes `.C', `.cc',
`.cpp', `.CPP', `.c++', `.cp', or `.cxx'; C++ header files often use
`.hh', `.hpp', `.H', or (for shared template code) `.tcc'; and
preprocessed C++ files use the suffix `.ii'. GCC recognizes files with
these names and compiles them as C++ programs even if you call the
compiler the same way as for compiling C programs (usually with the
name `gcc').

However, the use of `gcc' does not add the C++ library. `g++' is a
program that calls GCC and treats `.c', `.h' and `.i' files as C++
source files instead of C source files unless `-x' is used, and
automatically specifies linking against the C++ library. This program
is also useful when precompiling a C header file with a `.h' extension
for use in C++ compilations. On many systems, `g++' is also installed
with the name `c++'.
so, gcc will compile a c++ program to object code but won't link it (as already stated by markkuk)

(note also that g++ and c++ are identical (hardlinked) binaries in fedora)
Reply With Quote
  #8  
Old 18th April 2009, 05:00 PM
creeping death Offline
Registered User
 
Join Date: Feb 2008
Posts: 656
Quote:
Originally Posted by Anji_fedora View Post
Using pause I want to get effect of getch() (as in turbo C)
i think a simple scanf() or a getchar() would do the same thing as getch() - i.e wait for user input from stdin.
__________________
c_d -- superfluously plenteous yet indolently otiose

Last edited by creeping death; 18th April 2009 at 05:04 PM.
Reply With Quote
Reply

Tags
declared, scope, ‘system’

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
create on object whose name will be declared at run time. cbarmpar Programming & Packaging 6 14th September 2008 05:33 PM
wanted editor feature -- text search only within cursor code scope marko Programming & Packaging 3 17th May 2007 02:37 PM
Sharing Files by Connecting to a Linux System from a Windows System rvs1st Servers & Networking 2 20th October 2006 01:50 PM
simple DHCP scope for private LAN. Bluescreen Servers & Networking 0 1st August 2006 01:50 PM
File system cache becomming way to large and hanging the system...please help morph166955 Using Fedora 2 16th December 2005 09:45 PM


Current GMT-time: 16:02 (Wednesday, 23-07-2014)

TopSubscribe to XML RSS for all Threads in all ForumsFedoraForumDotOrg Archive
logo

All trademarks, and forum posts in this site are property of their respective owner(s).
FedoraForum.org is privately owned and is not directly sponsored by the Fedora Project or Red Hat, Inc.

Privacy Policy | Term of Use | Posting Guidelines | Archive | Contact Us | Founding Members

Powered by vBulletin® Copyright ©2000 - 2012, vBulletin Solutions, Inc.

FedoraForum is Powered by RedHat