LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 10-12-2004, 11:53 AM   #1
natm
Member
 
Registered: Sep 2004
Distribution: Ubuntu 7.04
Posts: 34

Rep: Reputation: 15
GCC problems


I am a C++ programmer and I am used to a windows IDE.
I have made the switch to linux but I want to know how to use GCC. I make the simplest of code that would work with codewarrior but when I compile it, I get all sorts of weird errors that I don't understand.

I am using the normal stuff:

#include<iostream.h>
void main()
{
cout<<"hello"<<endl;
}

normal things like this will not compile.

Last edited by natm; 10-12-2004 at 11:55 AM.
 
Old 10-12-2004, 12:10 PM   #2
jacksmash
Member
 
Registered: Nov 2003
Location: Ontario, Canada
Distribution: Ubuntu
Posts: 269

Rep: Reputation: 30
I'm having the same problem and would appreciate any pointers! (no pun intended)
 
Old 10-12-2004, 12:40 PM   #3
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
"all sorts of weird error messages" doesn't help us one bit. If you want any help solving problems you're gonna have to at least TELL us the problem. Post the error message.

[EDIT]
I'm pretty certain main() returns int, not void these days.

Last edited by Komakino; 10-12-2004 at 12:41 PM.
 
Old 10-12-2004, 01:17 PM   #4
natm
Member
 
Registered: Sep 2004
Distribution: Ubuntu 7.04
Posts: 34

Original Poster
Rep: Reputation: 15
first of all, I might be using the wrong command so it could yougive me the right command for compiling c++ programs?

I just type

gcc <filename>

but now that I think about it, I don't know how to specify where the compiled executable should go.
 
Old 10-12-2004, 01:28 PM   #5
Komakino
Senior Member
 
Registered: Feb 2004
Location: Somerset, England
Distribution: Slackware 10.2, Slackware 10.0, Ubuntu 9.10
Posts: 1,938

Rep: Reputation: 55
Quote:
Originally posted by natm
first of all, I might be using the wrong command so it could yougive me the right command for compiling c++ programs?

I just type

gcc <filename>

but now that I think about it, I don't know how to specify where the compiled executable should go.
You need to familiarise yourself with manual pages. Type:
man gcc
and you'll get the whole manual page for GCC (the gnu compiler collection). Most linux programs have a manual page and you access them in exactly the same way. It's q to quit, btw.

Right o, the command for compiling c++ is g++ not gcc. gcc will compile plain old vanilla C, not C++. So you want:
g++ <filename> -o executablename
If you don't specify the executable name you'll get an executable called a.out
 
Old 10-12-2004, 05:31 PM   #6
natm
Member
 
Registered: Sep 2004
Distribution: Ubuntu 7.04
Posts: 34

Original Poster
Rep: Reputation: 15
the file shows up after being compiled but I don't know how to execute it.
I have read, write, and execute permissions for it.
 
Old 10-15-2004, 02:56 PM   #7
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Run
./executablename
 
Old 10-15-2004, 11:48 PM   #8
DaHammer
Member
 
Registered: Oct 2003
Location: Planet Earth
Distribution: Slackware, LFS
Posts: 561

Rep: Reputation: 30
Re: GCC problems

Quote:
Originally posted by natm
I am a C++ programmer and I am used to a windows IDE.
I have made the switch to linux but I want to know how to use GCC. I make the simplest of code that would work with codewarrior but when I compile it, I get all sorts of weird errors that I don't understand.

I am using the normal stuff:

#include<iostream.h>
void main()
{
cout<<"hello"<<endl;
}

normal things like this will not compile.

Try:
Code:
#include <iostream>
using namespace std;
int main ()
{
  cout << "hello" << endl;
}
or
Code:
#include <iostream>
int main ()
{
  std::cout << "hello" << std::endl;
}
Code:
g++ hello.cpp -o hello
 
Old 10-17-2004, 09:42 PM   #9
natm
Member
 
Registered: Sep 2004
Distribution: Ubuntu 7.04
Posts: 34

Original Poster
Rep: Reputation: 15
Thanks, I got it to compile and run but I have one more question:

which header file do I use for getch() in linux?
 
  


Reply



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
Problems Compiling Problems With GCC And C++ phnxbn Linux - Software 0 11-02-2004 05:49 PM
cc (gcc) problems malbery Debian 2 08-23-2004 12:55 PM
GCC problems inanna Red Hat 4 04-28-2004 04:20 PM
GCC problems garf12 Linux - Software 1 03-07-2004 09:59 PM
gcc problems? b0lt Slackware 2 11-19-2003 07:07 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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