LinuxQuestions.org
Help answer threads with 0 replies.
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 06-30-2006, 08:54 AM   #1
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Rep: Reputation: 30
C++ in linux!


Hello, I need to learn in the next 15 days C++ completly (and I'm going to start A.S.A.P, I know other lang so it's just about the syntax different, right?)
I need to ask a few things first though :

1) What should I know as basic info when using C++ in linux?
2) Is there any difference between CPP in lin/win?
3) What is the recommended compiler in linux?
4) What is unique in C++, why was there even a need for this language? (Why didn't C was enough?)
5) Do you think I should know anything else? what?

Thanks!
 
Old 06-30-2006, 09:34 AM   #2
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
>I need to learn in the next 15 days C++ completly
dont you hate when you have to lie on an application for employment

>1) What should I know as basic info when using C++ in linux?
well you should know how to use g++ from the command line, including how to include header paths, and library locations.

>2) Is there any difference between CPP in lin/win?
there is no difference in c++ itself, however there are differences in compilers, headers, and os api.

>3) What is the recommended compiler in linux?
GCC's g++

>4) What is unique in C++, why was there even a need for this language? (Why didn't C was enough?)
are you serious.. this sounds like homework now.. but i guess it is summer.. c++ add the ability to easily write object oriented code, along with some other additional enhancements that you can read about.

>5) Do you think I should know anything else? what?
yeh there was one other thing, but i cant think of it now. hehe. no seriously though. 15 years probably wouldnt be enough let alone 15 days. just find some tutorials on the web and start coding.

good luck
 
Old 06-30-2006, 09:43 AM   #3
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by xhi
>I need to learn in the next 15 days C++ completly
dont you hate when you have to lie on an application for employment

>1) What should I know as basic info when using C++ in linux?
well you should know how to use g++ from the command line, including how to include header paths, and library locations.

>2) Is there any difference between CPP in lin/win?
there is no difference in c++ itself, however there are differences in compilers, headers, and os api.

>3) What is the recommended compiler in linux?
GCC's g++

>4) What is unique in C++, why was there even a need for this language? (Why didn't C was enough?)
are you serious.. this sounds like homework now.. but i guess it is summer.. c++ add the ability to easily write object oriented code, along with some other additional enhancements that you can read about.

>5) Do you think I should know anything else? what?
yeh there was one other thing, but i cant think of it now. hehe. no seriously though. 15 years probably wouldnt be enough let alone 15 days. just find some tutorials on the web and start coding.

good luck
haha//
Thanks dude,

anyways
> g++ from the command line, including how to include header paths, and library locations.
can you give an example?
user : g++ file.cpp fileout
?

what about the headers?
isn't it much easier to use a GUI compiler that points you out to where the problem (if there's one), is [why it doesn't compile, etc]??

>dont you hate when you have to lie on an application for employment
No man. I wasn't lying, to anyone. they just wanted me to learn cpp in the next 15 days (not as a guru, but atleast understand the language).
 
Old 06-30-2006, 09:55 AM   #4
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
yeh an example would be if you are writing and linking somthing to SDL. you would have to do something like. (ignoring the existance of sdl-config)
g++ -I/path/to/SDL/headers -L/path/to/SDL/LIBS -lSDL -lSDL_image file.cpp

so you should know how to add those locations of non standard headers with -I and nonstandard libs with -L and then specify the necessary libs with -l. that stuff is elementary, have to know it. along with other g++ command line options.

>isn't it much easier to use a GUI compiler that points you out to where the problem (if there's one), is [why it doesn't compile, etc]??
whoooaaa. do you know what kind of argument you will start with a statement like that .. either way you go, with cmd line, or gui you will get pointed to wehre the problem is. the ide does nothing special above what gcc/g++ does, it just wraps the output in a pretty package. from the cmd line you will get filename and line number.

imo you should start out on the cmd line, and get to know all about g++/gcc.. esp if you only have 15 days. you should spend 14 on the cmd line and 1 in an ide. unless you know what ide they will have you using and if you can get ahold of that you may be further ahead to use it for 15 days..


>No man. I wasn't lying, to anyone. they just wanted me to learn cpp in the next 15 days (not as a guru, but atleast understand the language).

thats the first thing that popped into my head, because everytime i have lied on one, i had to run home and learn somthing new. accelerated education at its best.
 
Old 06-30-2006, 09:58 AM   #5
xhi
Senior Member
 
Registered: Mar 2005
Location: USA::Pennsylvania
Distribution: Slackware
Posts: 1,065

Rep: Reputation: 45
also to follow up on the examples of command line stuff you should know. you should also have knowlege of how large project are compiled. like compiling to object files and then linking everything together. and you should also read up on using libraries.
 
Old 06-30-2006, 11:05 AM   #6
IndianaTux
LQ Newbie
 
Registered: Jan 2006
Location: Jasper, Indiana, USA
Distribution: Linux Mint 16 'Petra' Cinnamon
Posts: 26

Rep: Reputation: 15
Don't laugh, but I'd also suggest picking up a copy of "C++ for Dummies." It does an excellent job of taking you through the command line topics. (FYI - I had a C++ course in college, which was crap. I learned more about the fundamentals of C++ from this book than from that course). Anyway, the book comes with a CD which has a copy of the GNU compiler, though I believe it is the Win32 version. You can easily download the Linux version on the web. The CD also includes example code from the book. I wouldn't base everything you're learning on it - you would definitely benefit more by finding tutorials on the web - but I would definitely recommend it as a good starting point or as a reference tool.

Last edited by IndianaTux; 06-30-2006 at 11:10 AM.
 
Old 06-30-2006, 12:32 PM   #7
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,379

Rep: Reputation: 148Reputation: 148
Quote:
Originally Posted by itz2000
4) What is unique in C++, why was there even a need for this language? (Why didn't C was enough?)
I'm sure I'm going to miss something here but C++ was added to provide different paradigms to support the programmer. That means you need to be comfortable with those ways of thinking. So there is procedural programming (just as there is in C) then there is object-oriented programming (classes, objects, inheritance, encapsulation, polymorphism), next comes generic programming (templates) Then there is modular programming (header files, namespaces & exceptions).

I think that's it, but maybe I forgot something. It may be possible to learn the syntax in 15 days but not to understand its meaning.
 
Old 06-30-2006, 01:31 PM   #8
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
lets say I got this code, and I want to compile(and run) it from terminal (I already got g++ installed)

Code:
hello.cpp :


#include <iostream>
using namespace std;

int main () {
         cout << "Hello World!" << endl;
         return 0;
}
what shall I do from start to finish (compile, linking, whatever)
...

Last edited by itz2000; 06-30-2006 at 01:35 PM.
 
Old 06-30-2006, 01:35 PM   #9
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Do you have a question about this? You use "g++ hello.cpp", but then the executable will be called a.out. If you want to choose what the executable is called, use g++'s o option: "g++ hello.cpp -o hello" will create an executable called hello.
 
Old 06-30-2006, 05:15 PM   #10
dive
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Slackware
Posts: 3,467

Rep: Reputation: Disabled
You may find these 2 tuts helpful:

http://www.cprogramming.com/tutorial/lesson1.html
http://www.cplusplus.com/doc/#tutorial
 
Old 06-30-2006, 07:12 PM   #11
spursrule
LQ Newbie
 
Registered: Feb 2006
Distribution: LFS
Posts: 26

Rep: Reputation: 15
You can make a makefile and just type make or make all to build the code

Here's an example makefile: (just call it Makefile or makefile)

Code:
obj=hello.o
exe=hello

all:
     g++ -o $(exe) $(obj)

hello.o:  hello.cpp
     g++ -c hello.cpp

clean:
     -rm -f $(exe) $(obj)
all is the default done when you type make and hit enter, and this links the object file(s) into an executable

g++ -c compiles to an object file
g++ -o links object files into an executable

If you leave out the name in g++ -o name $(obj) (here it is $(exe)), your executable will be named a.out

in the line hello.o: hello.cpp , hello.o is the name of the file built, and any names following the : are files it depends on (here, hello.cpp). The next line is a tab, followed by the command to build hello.o from hello.cpp.

all is the default target as I said earlier, and depends on the object files $(obj) (in this case, hello.o)

The target clean has no dependencies, and the - in front of the rm tells make to not bail out if a file can't be deleted (ie, say you want to clean out all the object files from a failed build that didn't produce an executable, you can still type make clean)

You could also call all anything you want... ie, you could change it to love, and then build your executable using make (assuming love is the first target) or make love.

Last edited by spursrule; 06-30-2006 at 07:13 PM.
 
Old 07-01-2006, 12:12 AM   #12
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
If it's a really basic program like a "hello world", is there really any need to use a makefile?
 
Old 07-01-2006, 03:43 AM   #13
itz2000
Member
 
Registered: Jul 2005
Distribution: Fedora fc4, fc7, Mandrake 10.1, mandriva06, suse 9.1, Slackware 10.2, 11.0, 12.0,1,2 (Current)]
Posts: 732

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Nylex
If it's a really basic program like a "hello world", is there really any need to use a makefile?
Like I said, I'm going to use more then a basic use,
So I need to know what it's best to do even when it comes to more complicated programs!
Anyways, I liked g++ (very similar to gcc)..
but I'd like to have also, as a backup, GUI compiler...

what's the name of the best GUI compiler for C++??

Thanks..
 
Old 07-01-2006, 05:32 AM   #14
traene
Member
 
Registered: Jan 2005
Distribution: Archlinux, Debian, Centos
Posts: 222

Rep: Reputation: 35
maybe have a look at kdevelop. It uses gcc/g++ (actually the same compiler package). I haven't any experience with it, though.
Also have a look at the qt - Designer, if you want to design a GUI frontend. But this may be included in the kdevelop.
Drawback: You may be relying a bit to much on kde libraries. Another GUI package could be the GTK like libraries like used ont the GNOME window manager.
 
Old 07-01-2006, 12:47 PM   #15
spursrule
LQ Newbie
 
Registered: Feb 2006
Distribution: LFS
Posts: 26

Rep: Reputation: 15
Quote:
Originally Posted by Nylex
If it's a really basic program like a "hello world", is there really any need to use a makefile?
If you get used to writing makefiles for small things it'll make it a lot easier when you're doing a project where it's necessary.
 
  


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
link dies intermittently-seemingly at random- between win<->linux not linux<->linux?? takahaya Linux - Networking 10 03-09-2007 10:37 PM

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

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