LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-24-2005, 06:08 AM   #1
malb
LQ Newbie
 
Registered: Jul 2005
Posts: 10

Rep: Reputation: 0
Please help I can't compile c++ file


Hi

I recetly installed g++ on Fedora. (I used "yum install gcc-c++"). It seemed to be fine but if I try to compile the following very simple c++ code, it just gives me an error mesage sayng "expected constructor, destructor, or type conversion before < token"...

#include <iostream>
using namespace std;

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


I'm a newbie and don't know what to do.. Please help me.

Last edited by malb; 07-24-2005 at 07:27 AM.
 
Old 07-24-2005, 07:17 AM   #2
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
What is the command you're using to compile? The code looks fine to me. Edit: also, this should have been in the Programming forum.

Last edited by Nylex; 07-24-2005 at 07:20 AM.
 
Old 07-24-2005, 07:26 AM   #3
malb
LQ Newbie
 
Registered: Jul 2005
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks for reply.

I used "g++ HelloWorld.cpp".
 
Old 07-24-2005, 07:39 AM   #4
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
You should be using:
Code:
g++ SOURCE_FILE.CPP -o OUTPUT_FILE
Where SOURCE_FILE.CPP is the name of your source code, and OUTPUT_FILE is the executable. In the above example, you'd want this command:
Code:
g++ HelloWorld.cpp -o HelloWorld
 
Old 07-24-2005, 07:42 AM   #5
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Using "g++ HelloWorld.cpp" is fine, just the executable will be called a.out.
 
Old 07-24-2005, 08:26 AM   #6
malb
LQ Newbie
 
Registered: Jul 2005
Posts: 10

Original Poster
Rep: Reputation: 0
exactly...

"g++ filename.cpp -o filename" doesn't work either.
 
Old 07-24-2005, 08:16 PM   #7
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
What are the compiler errors?
 
Old 07-24-2005, 09:43 PM   #8
foo_bar_foo
Senior Member
 
Registered: Jun 2004
Posts: 2,553

Rep: Reputation: 52
Quote:
Originally posted by scuzzman
What are the compiler errors?
yea we need exact error messages copy and pasted
 
Old 07-24-2005, 10:57 PM   #9
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
"expected constructor, destructor, or type conversion before < token" comes from the compiler. I found loads of similar errors when searching Google, but no way to fix them. Maybe his GCC is broken, or something.
 
Old 07-25-2005, 06:52 PM   #10
malb
LQ Newbie
 
Registered: Jul 2005
Posts: 10

Original Poster
Rep: Reputation: 0
Thanks heaps.

I just re-installed gcc and it's fine now.
 
  


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
how to compile a tex-file ?? Lise Linux - Newbie 3 02-27-2005 12:20 PM
How do I compile a source file? Mal495 Debian 6 07-20-2004 07:07 AM
font problems, halp mrb Linux - Newbie 1 05-15-2004 01:12 PM
Compile to .class file AMMullan Programming 1 03-31-2004 04:59 AM
Halp Mandrake MNF question SSBN Linux - Networking 0 06-15-2003 11:29 PM


All times are GMT -5. The time now is 11:44 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration