?
Solved

simple gcc error

Posted on 2003-03-25
5
Medium Priority
?
226 Views
Last Modified: 2010-04-21
Just installed Red Hat 8.0.  This may be the problem since I'm a Solaris guy.  I'm not a C++ programmer either, but I wanted to try a little code on Red Hat.

GCC will not compile a simple C++ program and gives me a compilation error after the command:
#gcc foo.cpp -o foo

My program is simply:

#include <iostream>

using namespace std;

int main()
{
     cout << "Foo!";
     return 0;
}

And when running gcc with the parameters above, I get "undefined regerence to 'std:cout' and 'std:basic_ostream....'

When removing "using namespace std" I get " 'cout' undeclared" as if it does not exist

Anyone see a problem with what I'm doing?  Don't be afraid to tell me the obvious!
0
Comment
Question by:themobileman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 3

Expert Comment

by:prady_21
ID: 8208413
#include<iostream.h>

The name of the header file is "iostream.h"
hope it helps
0
 
LVL 1

Author Comment

by:themobileman
ID: 8208433
Thanks, but iostream.h doesn't work either
0
 
LVL 1

Author Comment

by:themobileman
ID: 8208435
Thanks, but iostream.h doesn't work either
0
 

Accepted Solution

by:
vmaster earned 200 total points
ID: 8210619
The problem is that you don't link against the C++ libraries. To do so, either compile using the C++ compiler g++ (gcc is just a frontend to the various compilers behind) or link the required libraries explicitly, using -lstdc++ on the gcc command line:

gcc foo.cpp -o foo -lstdc++

or

g++ foo.cpp -o foo
0
 
LVL 1

Author Comment

by:themobileman
ID: 8211870
That works!  Thanks!
0

Featured Post

What is a Denial of Service (DoS)?

A DoS is a malicious attempt to prevent the normal operation of a computer system. You may frequently see the terms 'DDoS' (Distributed Denial of Service) and 'DoS' used interchangeably, but there are some subtle differences.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question