LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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 07-04-2003, 01:39 AM   #1
crisponions
LQ Newbie
 
Registered: Feb 2002
Distribution: RedHat (currently 9.0)
Posts: 29

Rep: Reputation: 15
Question C++ & linux - newbie


I just started teaching myself c++ and have been doing most of my compiling on a windows machine. I thought I would give it a try with linux but am having problems.

The standard
#include <iostream.h>

int main()
{
cout << "Hello World!" << endl;
return 0;
}

wont compile. I have seen posts about dropping the h from the iostream and "include namespace std" but none of that seems to work either. I though c++ was supposed to be pretty platform independant. I really dont want to have to learn to code one way for windows and another for linux.

Last edited by crisponions; 07-04-2003 at 01:42 AM.
 
Old 07-04-2003, 01:53 AM   #2
nakkaya
LQ Guru
 
Registered: Jan 2003
Location: Turkey&USA
Distribution: Emacs and linux is its device driver(Slackware,redhat)
Posts: 1,398

Rep: Reputation: 45
compiles on my machine code is correct what is the command u are using to compile
 
Old 07-04-2003, 01:57 AM   #3
crisponions
LQ Newbie
 
Registered: Feb 2002
Distribution: RedHat (currently 9.0)
Posts: 29

Original Poster
Rep: Reputation: 15
just gcc. suing version 3.2.2-5
 
Old 07-04-2003, 01:59 AM   #4
shellcode
Member
 
Registered: May 2003
Location: Beverly Hills
Distribution: Slackware, Gentoo
Posts: 350

Rep: Reputation: 32
g++ is the command you want to use.
 
Old 07-04-2003, 02:06 AM   #5
crisponions
LQ Newbie
 
Registered: Feb 2002
Distribution: RedHat (currently 9.0)
Posts: 29

Original Poster
Rep: Reputation: 15
That did it thanks!
 
Old 07-04-2003, 01:49 PM   #6
Cyclo
Member
 
Registered: Jul 2003
Distribution: Slackware 9.1
Posts: 47

Rep: Reputation: 15
If you want to make GUI programs, try using Qt - free and simple
 
Old 07-04-2003, 02:37 PM   #7
tcaptain
LQ Addict
 
Registered: Jul 2002
Location: Montreal
Distribution: Gentoo 2004 from stage 1 baby!
Posts: 1,403

Rep: Reputation: 45
Quote:
Originally posted by Cyclo
If you want to make GUI programs, try using Qt - free and simple
QT is fun and simple enough (I'm learning it now...sort of...off and on) but I think it would be important to get the basic C++ down first before trying to use a toolkit like that so that you can understand how the toolkit is doing what its doing no?
 
Old 07-05-2003, 09:52 AM   #8
Cyclo
Member
 
Registered: Jul 2003
Distribution: Slackware 9.1
Posts: 47

Rep: Reputation: 15
my basis for recommending it is it drastically simplifies string handling etc, and it's tutorials are relatively good.

also, great book is "Learn C++ for linux in 21 days"
 
Old 07-05-2003, 11:38 AM   #9
crisponions
LQ Newbie
 
Registered: Feb 2002
Distribution: RedHat (currently 9.0)
Posts: 29

Original Poster
Rep: Reputation: 15
I am using "teach yourself c++ in 21 days". But thanks for the info on qt, I will definately check it out once I get through the basics.
 
Old 07-05-2003, 09:13 PM   #10
tcaptain
LQ Addict
 
Registered: Jul 2002
Location: Montreal
Distribution: Gentoo 2004 from stage 1 baby!
Posts: 1,403

Rep: Reputation: 45
Quote:
Originally posted by Cyclo
my basis for recommending it is it drastically simplifies string handling etc, and it's tutorials are relatively good.

also, great book is "Learn C++ for linux in 21 days"
For THAT I agree...in fact I just managed to get my first QT project to work today so I'm pretty jazzed about it (Its just a dinky little thing but it's fun to work on...). I'm really liking the QString class now that I have the hang of it, although I stand by what I said, QT isn't for someone who doesn't know the basics...BUT, once you know..it's easy to get into...

A great book that I recommend (along with the others mentionned which I also have) is Tom Swan's 'GNU C++ for Linux'. Until I had found that book I had been rather frustrated by the windows-centric leanings of the other books (although that's a minor gripe since by and large, C++ is C++ for the basics). This book is totally awesome for the beginner programmer using linux. If you have to choose only one book, that's the one I'd go with.
 
Old 07-06-2003, 02:42 PM   #11
mandolin
LQ Newbie
 
Registered: Jul 2003
Posts: 2

Rep: Reputation: 0
Unhappy

Well, I tried compiling your 'hello world!' code with gcc (>gcc test.cpp) and got a whole load of linker errors. I'm hardly an expert myself and I'm not sure why they're there.

Just using the c++ compiler worked fine (>c++ test.cpp), although you will need to add the 'using namespace std' into your code. That might do you for a while but you really should be able to use gcc.

What distro do you use (I'm using mandrake)?

Anyone else out there that's cleverer than me care to shed some light on the situation?
 
Old 07-06-2003, 02:44 PM   #12
mandolin
LQ Newbie
 
Registered: Jul 2003
Posts: 2

Rep: Reputation: 0
wow, posts come thick and fast here don't they!
 
Old 07-06-2003, 03:45 PM   #13
Proud
Senior Member
 
Registered: Dec 2002
Location: England
Distribution: Used to use Mandrake/Mandriva
Posts: 2,794

Rep: Reputation: 116Reputation: 116
A 5.5 hour gap is fast?
 
Old 07-06-2003, 06:19 PM   #14
crisponions
LQ Newbie
 
Registered: Feb 2002
Distribution: RedHat (currently 9.0)
Posts: 29

Original Poster
Rep: Reputation: 15
Quote:
Well, I tried compiling your 'hello world!' code with gcc (>gcc test.cpp) and got a whole load of linker errors. I'm hardly an expert myself and I'm not sure why they're there.

Just using the c++ compiler worked fine (>c++ test.cpp), although you will need to add the 'using namespace std' into your code. That might do you for a while but you really should be able to use gcc.

What distro do you use (I'm using mandrake)?
I am using RedHat 9. The g++ compiler took care of my problem.

So am I correct in assuming gcc is for c programs?
 
Old 07-06-2003, 08:47 PM   #15
shellcode
Member
 
Registered: May 2003
Location: Beverly Hills
Distribution: Slackware, Gentoo
Posts: 350

Rep: Reputation: 32
Quote:
Originally posted by crisponions

So am I correct in assuming gcc is for c programs?
you are.
 
  


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
Firestarter & Linux newbie Lame Linux - Security 1 08-25-2004 08:37 AM
Yes, I am a los & linux newbie in need of help! Nishtya Linspire/Freespire 7 04-25-2004 04:27 AM
Newbie & Linux dufus wants to know: which Linux version has the best GUI? Ma-fia Linux - Newbie 20 03-04-2004 09:59 PM
newbie comcast & linux?? preludedude Linux - Networking 2 02-26-2004 02:28 PM
Linux & Nforce newbie!! tbob419 Linux - Newbie 10 03-31-2003 05:06 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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