LinuxQuestions.org
Visit Jeremy's Blog.
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 08-09-2009, 09:02 PM   #1
bskumar7080
Member
 
Registered: Aug 2009
Distribution: Mandriva
Posts: 57

Rep: Reputation: 15
Question How to compile C/C++


How to compile C/C++ programs. Is there any IDE similar to Turboc in Linux.. I am using mandriva spring 2009.
 
Old 08-09-2009, 09:26 PM   #2
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
From what I've read, a lot of people use an IDE like Eclipse or Anjuta or something similar.
 
Old 08-09-2009, 10:31 PM   #3
gregorian
Member
 
Registered: Apr 2006
Posts: 509

Rep: Reputation: 34
For now, type the program in a simple text editor, and save the file as .c (for C programs) or .cpp (for C++ programs). Open the terminal (this is like the Command Prompt in Windows) and type gcc program.cc or g++ program.cpp to compile the program. If you have no errors, type ./a.out and press enter.

I see you're used to Turbo C. You've got to learn a few things before you use gcc/g++ since Turbo C adheres to the old standards.

Search for hello world gcc or something along those lines.

Last edited by gregorian; 08-09-2009 at 10:32 PM.
 
Old 08-10-2009, 06:41 AM   #4
jeromeNP7
Member
 
Registered: Jun 2009
Posts: 101

Rep: Reputation: 19
The LCC compiler is available for both Linux and Windows and it allows you to maintain complete projects. On Linux it makes sense to read a few tutorials about makefiles, so that you can write these by hand until you settled for any IDE.

Linux

Last edited by jeromeNP7; 09-04-2009 at 09:05 PM.
 
Old 08-10-2009, 07:08 AM   #5
bskumar7080
Member
 
Registered: Aug 2009
Distribution: Mandriva
Posts: 57

Original Poster
Rep: Reputation: 15
[Thank you
 
Old 08-10-2009, 07:13 AM   #6
rkirk
LQ Newbie
 
Registered: Apr 2009
Posts: 26

Rep: Reputation: 23
As has already been said, doing it manually is the best for simple projects, though it's perhaps easier to specify a name for the output binary using the -o flag.

Code:
$ gcc helloworld.c -o helloworld.o
Code:
$ g++ helloworld.cpp -o helloworld.o
Of course, for anything more complex than a "hello world" or a financial calculator, you'll want to use makefiles. Here's a nice introduction to writing Make files.
 
Old 08-10-2009, 07:45 AM   #7
bskumar7080
Member
 
Registered: Aug 2009
Distribution: Mandriva
Posts: 57

Original Poster
Rep: Reputation: 15
I am new to linux, i was able to compile and run C programs. How to compile and run C++ programs..
 
Old 08-10-2009, 08:01 AM   #8
rkirk
LQ Newbie
 
Registered: Apr 2009
Posts: 26

Rep: Reputation: 23
You will most likely need to install g++ and use it as you would the gcc command because it does not come by default on many systems.

On a slightly more advanced note, there are also different make utilities, such as cmake, qmake, and mk, all of which have their own specific purposes.
 
Old 08-10-2009, 01:54 PM   #9
joeBuffer
Member
 
Registered: Jul 2009
Distribution: Ubuntu 9.04
Posts: 328

Rep: Reputation: 42
I've also noticed that some distributions don't have g++ in their repositories by that name ... openSUSE is one of them. You have to install the gcc-c++ package, or something similar. the GNU programs c++ and g++ are different names for the same program.
 
  


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
[Compile kernel] How to compile/install the modules ? frenchn00b Linux - General 1 09-06-2009 03:18 PM
Trying to patch kernel + compile, compile is looping. kripz Linux - Kernel 1 06-16-2009 06:51 AM
CLFS 5.9 - Glibc compile: suffix of object files, cannot compile Noddegamra Linux From Scratch 3 04-27-2009 12:49 AM
how to compile software for any other Linux box which is do not have compile? hocheetiong Linux - Newbie 4 03-06-2009 04:35 PM
ntop compile/post-compile problem? tjb Linux - Software 3 12-28-2004 04:22 PM


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