LinuxQuestions.org
Help answer threads with 0 replies.
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 03-13-2005, 09:10 PM   #1
krock923
Member
 
Registered: Jul 2004
Posts: 171

Rep: Reputation: 30
gcc problem


Hi, i'm having a little problem with gcc and headers. I'm trying to learn C++ and when I try to compile a simple hello world with gcc, it yells at me for using iostream.h but when I #include<iostream>, it (i assume, because it says first use of cout when compiling) can't find it. I don't know where header files are kept on a linux system or even how i would go about updating gcc because i probably should considering that this is the one on the original cds from redhat 9. Thanks in advance.
 
Old 03-13-2005, 09:18 PM   #2
linuxzealot
Member
 
Registered: Feb 2005
Distribution: Gentoo
Posts: 57

Rep: Reputation: 15
gcc searches these places for header files

/usr/local/include
/usr/lib/gcc-lib/target/version/include
/usr/target/include
/usr/include
/usr/include/g++-v3

As far as updating gcc, Im sure redhat has an rpm for it
 
Old 03-13-2005, 09:29 PM   #3
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
iostream is not in any of those. when i searched for it as root, it was in the following locations:

./usr/include/g++-3/iostream
./usr/include/c++/3.2.2/iostream

however, the exact same directories came up for iostream.h and the compile worked fine (except for naggin me about the old header) when I used that.
 
Old 03-13-2005, 09:38 PM   #4
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
here is the program. . . can't get much more simple than this:

Code:
#include<iostream>

int main ()
{
cout << "Hello, World!" <<endl;

return 0;
}
here is the return from the console when i try to compile it:

Code:
 g++ hello.C -o hello
hello.C: In function `int main()':
hello.C:5: `cout' undeclared (first use this function)
hello.C:5: (Each undeclared identifier is reported only once for each function
   it appears in.)
hello.C:5: `endl' undeclared (first use this function)
hello.C:8:2: warning: no newline at end of file
Is there any difference between g++ and gcc. btw? Each way gave me the same error output.
 
Old 03-13-2005, 10:05 PM   #5
linuxzealot
Member
 
Registered: Feb 2005
Distribution: Gentoo
Posts: 57

Rep: Reputation: 15
You need to put a space you have

Code:
#include<iostream>
(or at least it looks like it)

this is what you should have

Code:
#include <iostream>
 
Old 03-13-2005, 10:08 PM   #6
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
That still gave me the same error message when I tried to compile.
 
Old 03-13-2005, 10:13 PM   #7
linuxzealot
Member
 
Registered: Feb 2005
Distribution: Gentoo
Posts: 57

Rep: Reputation: 15
Just out of curiosity, try #include <iostream.h> and see what that does
 
Old 03-13-2005, 10:22 PM   #8
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
it compiled, but with this message:

g++ hello.C -o hello
In file included from /usr/include/c++/3.2.2/backward/iostream.h:31,
from hello.C:1:
/usr/include/c++/3.2.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 <sstream> instead of the deprecated header <strstream.h>. To disable this warning
use -Wno-deprecated.
 
Old 03-13-2005, 10:24 PM   #9
linuxzealot
Member
 
Registered: Feb 2005
Distribution: Gentoo
Posts: 57

Rep: Reputation: 15
You need to update gcc, and get the new header files, I think you are missing some things.
 
Old 03-13-2005, 10:25 PM   #10
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
okay thanks. where could i get a new version from? Could this also explain why it's screwing up other things as well?
 
Old 03-13-2005, 10:29 PM   #11
linuxzealot
Member
 
Registered: Feb 2005
Distribution: Gentoo
Posts: 57

Rep: Reputation: 15
http://rpmfind.net/linux/rpm2html/search.php?query=gcc

And older versions of gcc can defintly be a problem with apps screwing up
 
Old 03-14-2005, 03:24 PM   #12
aditya1
Member
 
Registered: Mar 2005
Location: College station, Texas
Distribution: UBUNTU 10.04
Posts: 61

Rep: Reputation: 15
try this i twill surely help you


#include<iostream>
using namespace std;
int main()
{//write your program
}
 
Old 03-14-2005, 04:00 PM   #13
krock923
Member
 
Registered: Jul 2004
Posts: 171

Original Poster
Rep: Reputation: 30
Quote:
Originally posted by aditya1
try this i twill surely help you


#include<iostream>
using namespace std;
int main()
{//write your program
}
Wow, that worked. No errors now. That is very good because I'm using RedHat9 and updating gcc would have required me to also upgrade so much other stuff that I was going to do an entire OS upgrade. I didn't really feel like doing that.

Actually, is RH9 now so old that I should do an OS upgrade anyway?
 
Old 03-15-2005, 08:28 AM   #14
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
As you noticed, the reason that <iostream> didn't work for you, but <iostream.h> did is because <iostream> puts everything into the std namespace. Adding the line "using namespace std;" is one way to cause it to inject everything in the std namespace into the global namespace.

Alternatively, you could have used std::cout and std::endl, to explicitly specify the namespace that they are in.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Solved Problem Second GCC-Pass(or gettext sanity check problem) hoes Linux From Scratch 0 09-04-2005 10:20 AM
problem with gcc or me? kahn Programming 6 06-13-2005 03:20 AM
GCC problem HiOctane21 Linux - Newbie 2 02-19-2004 05:55 PM
gcc 3.2-7 problem necromancer Programming 7 03-04-2003 01:04 PM
GCC problem drjimstuckinwin Linux - General 1 08-23-2001 06:43 AM

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

All times are GMT -5. The time now is 01:09 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