LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 10-12-2004, 01:43 PM   #1
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
simple c++/gcc problem


I just installed Fedora Core, and I'm having trouble compiling simple c++ programs. For example:

#include <iostream>
using namespace std;

int main()
{
cout << "test\n";
return 0;
}

-- something as basic as this gives me compile errors, such as cout is not part of the std namespace etc..

-- yes, I have tried iostream.h as well


How do I tell what version of gcc I'm using?

Does anyone have any suggestions for me?

Thanks!
 
Old 10-12-2004, 01:58 PM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
How are you compiling it?

gcc --version will tell you what version of gcc your running.

Btw.. for C++ files use g++ not gcc (yes, I know, g++ is the same as gcc with a couple of switches...).
 
Old 10-12-2004, 02:03 PM   #3
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
Using g++ solved my problems.

Thanks for the suggestion!

Cheers.
 
Old 10-12-2004, 02:03 PM   #4
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
How are you trying to compile and which error messages are you getting from the compiler? You do know that this are very important details .

Anyway, to find out your gcc version, or any other rpm package:

rpm -qa | grep <name of what you are looking for>

some applications also show it's version by typing:

application_name -v or -version

You could alway try man application_name for a fully detailed explanation of how to use the application in question...

Examples of compiling a cpp code with g++:

g++ -o executable hello.cpp

that's for c++ code. Many user try with gcc to compile c++ code:

gcc -o executable hello.cpp

That won't work. That first code will compile your code, link and create an executable (here smartly called "executable", but could be anything you want) which you can run with ./executable.

I hope it helps.

---------------

How to ask questions, the smart way

Posting and You...
 
Old 10-12-2004, 02:10 PM   #5
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Original Poster
Rep: Reputation: 30
You both have been a lot of help. Much appreciated.
 
Old 10-12-2004, 02:13 PM   #6
Mega Man X
Guru
 
Registered: Apr 2003
Location: ~
Distribution: Ubuntu, FreeBSD, Solaris, DSL
Posts: 5,339

Rep: Reputation: 63
Sorry that I re-answered you jtshaw . He was faster. I surely do, have to start clicking in that refresh button before posting .

I'm glad it works for you jacksmash
 
  


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
can't compile simple C++ programs on Suse 9.1 after installing gcc cyclebain Linux - Software 9 07-04-2007 09:04 AM
Solved Problem Second GCC-Pass(or gettext sanity check problem) hoes Linux From Scratch 0 09-04-2005 11:20 AM
simple gcc question davidleroux1 Programming 1 07-26-2005 11:46 PM
Trouble Compiling a simple Hellow World on Solaris 9 with GCC 3.4.2 jitendra64 Solaris / OpenSolaris 4 10-11-2004 03:57 PM
Can't get a simple C function to work with GCC chris.hicks Programming 3 10-29-2003 12:09 PM


All times are GMT -5. The time now is 07:26 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration