LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-19-2009, 03:57 AM   #1
sach1n
LQ Newbie
 
Registered: Nov 2009
Location: Mumbai, India
Distribution: Slackware-13,Slackware64-13.37,Vector linux
Posts: 14

Rep: Reputation: 0
Red face Problem in compiling c++ prg's


Hey Slacker pls help me !

I've installed Slackware 13[DVD-whole setup]
which include gcc-base and gcc-g++
but I've problem compiling even a simple "Hello world" prg in g++.
It show the error msg:
error in function main():
'cout' was not declared in the scope
'endl' was not declared in the scope

The gcc (.c) files are fine

I've tried installing the whole pkgs of 'gcc' many times
even the OS

but it's not helping
I want help in urgent

uname -a: --->
linux-2.29.x-smp AMD Athlon 64x2 Dual core
 
Old 11-19-2009, 04:03 AM   #2
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Have you remembered to #include <iostream> and included the line 'using namespace std;'?

e.g:
Code:
#include <iostream>

using namespace std;

void main(int argc, char** argv){
 cout << "Hello world" << endl;
}

Also make sure you're calling g++ to compile it. gcc is the C compiler, not the C++ compiler.
 
Old 11-19-2009, 07:45 AM   #3
escaflown
Member
 
Registered: Apr 2009
Location: Canada
Distribution: Slackware
Posts: 239

Rep: Reputation: 31
It's simply a programming error. Like Komakino said it, you probably didn't use the iostream library or the std namespace. In C++, cout and endl are defined in the std namespace (using namespace std; ) and you also need to include iostream library ( #include <iostream>). You can find a good C++ tutorial at http://www.learncpp.com/

Quote:
Originally Posted by sach1n View Post
Hey Slacker pls help me !

I've installed Slackware 13[DVD-whole setup]
which include gcc-base and gcc-g++
but I've problem compiling even a simple "Hello world" prg in g++.
It show the error msg:
error in function main():
'cout' was not declared in the scope
'endl' was not declared in the scope

The gcc (.c) files are fine

I've tried installing the whole pkgs of 'gcc' many times
even the OS

but it's not helping
I want help in urgent

uname -a: --->
linux-2.29.x-smp AMD Athlon 64x2 Dual core
 
Old 11-19-2009, 08:48 AM   #4
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 8,559

Rep: Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106Reputation: 8106
I fail to see how this is a Slackware issue. Can this thread be moved to the programming forum?

Eric
 
Old 11-19-2009, 08:53 AM   #5
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Quote:
Originally Posted by Alien Bob View Post
I fail to see how this is a Slackware issue. Can this thread be moved to the programming forum?

Eric
I believe the OP thought his issue was related to not having the correct slack packages installed, but you're right in that this isn't a Slackware specific issue and should probably be moved.
 
Old 11-19-2009, 09:26 AM   #6
XavierP
Moderator
 
Registered: Nov 2002
Location: Kent, England
Distribution: Debian Testing
Posts: 19,192
Blog Entries: 4

Rep: Reputation: 475Reputation: 475Reputation: 475Reputation: 475Reputation: 475
In light of the above, moved to Programming
 
Old 11-19-2009, 11:50 AM   #7
smeezekitty
Senior Member
 
Registered: Sep 2009
Location: Washington U.S.
Distribution: M$ Windows / Debian / Ubuntu / DSL / many others
Posts: 2,339

Rep: Reputation: 231Reputation: 231Reputation: 231
have you included iostream? or iostream.h if using the old standard?
 
Old 11-20-2009, 11:46 PM   #8
sach1n
LQ Newbie
 
Registered: Nov 2009
Location: Mumbai, India
Distribution: Slackware-13,Slackware64-13.37,Vector linux
Posts: 14

Original Poster
Rep: Reputation: 0
Thumbs up

As escaflown said that this is a simple programming issue, but I've never got this kind of problem on my Linux Mint.

What will be the reason for this ??

Any way's thanks Komakino for such a fast reply

Thank you all
 
Old 11-21-2009, 12:41 AM   #9
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
A compiler that doesn't implement the C++ standard correctly would be my guess (on your other installation.)
Kevin Barry

edit: That is to say: If this exact code compiled on LM, it's probably a non-standard compiler. Otherwise, I'd guess you're mistaken.

Last edited by ta0kira; 11-21-2009 at 12:43 AM.
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
problem compiling with rt.2.6.9 rem1986 Linux - Kernel 0 08-26-2006 03:27 PM
Problem while compiling shinni Programming 1 02-08-2005 12:13 AM
compiling problem ... chaks Programming 2 03-29-2004 09:14 AM
Compiling Problem BACTRATE Mandriva 1 03-12-2004 04:36 AM
compiling problem with RH 9 tucdual Linux - Distributions 4 08-26-2003 07:03 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:08 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration