Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

simple gcc error

Posted on 2003-03-25
5
Medium Priority
?
227 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
  • 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

564 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