How to install C/C++ compiler in Ubuntu

A Place For Programmers Of All Levels To Discuss Programming & Web Building.

Moderator: Community Moderator

Post Reply
User avatar
thecakeisalie
Corporal
Corporal
Posts: 42
Joined: 20 Sep 2010, 22:56
Has thanked: 8 times
Been thanked: 4 times

How to install C/C++ compiler in Ubuntu

Post by thecakeisalie »

I cannot take credit for this tutorial, as I learned it from another site. All credit goes to the guy at Ubuntu Geek. I simply want to show others how to, who may be a Linux noob like myself. I can provide the source link if anyone is interested. Alright, lets get started.

(I am using the latest version of Ubuntu 10.10, your commands may vary depending on your distribution)

First we need to open the command prompt by clicking Applications > Accessories > Terminal

With the terminal open type the following command:

Code: Select all

sudo apt-get install build-essential
You may or may not be prompted to type in your password

The install process will then start:

Image

Once the install has finished, it is time to create your first program.

(In this case I created a C++ program. You can also create C programs, however not with this method. I apologise, I will not be showing you how to create a C program as I am not familiar with the C language)

Lets do so by typing:

Code: Select all

sudo gedit <name of your program goes here> .cpp
(no space between the .cpp and the name of you program)

A text editor will then open up like so and you can then type in you program. Save your program when done:

Image

You can copy this code if you like:

Code: Select all

#include <iostream>

using namespace std;

int main()
{

   cout << "Hello world!" << endl; 

return 0;
}
Now to compile your program we must type:

Code: Select all

g++ <name of your program>.cpp -o test
(That is the letter O)

If you copied the code correctly then you will see the next prompt username@computer:~$
However, if there are any errors they will be shown on the next prompt. For example:

Image

Once all errors have been corrected you can now run your program by typing:

Code: Select all

./test
Depending on your program you will get some output in the terminal:

Image

I hope that helps, now go get your programming on.
Last edited by thecakeisalie on 26 Nov 2010, 11:31, edited 6 times in total.
Image

The right man in the wrong place can make all the difference in the world
- G-Man


Image
User avatar
LadyHawke
Th3 M0th3r
Th3 M0th3r
Posts: 10602
Joined: 08 Nov 2009, 08:58
Location: The Land of the Gods!
Has thanked: 17 times
Been thanked: 15 times
Contact:

Re: How to install C/C++ compiler in Ubuntu

Post by LadyHawke »

I'm not a Linux expert and I cannot judge if the tut is good or not but thank you for your contribution to the programming forum :)
CC Total Customization! | Read The Rules

~If you don't have the capacity to give, you shouldn't have the audacity to take~
User avatar
thecakeisalie
Corporal
Corporal
Posts: 42
Joined: 20 Sep 2010, 22:56
Has thanked: 8 times
Been thanked: 4 times

Re: How to install C/C++ compiler in Ubuntu

Post by thecakeisalie »

LadyHawke wrote:I'm not a Linux expert and I cannot judge if the tut is good or not but thank you for your contribution to the programming forum :)
No prob :blush:
Last edited by thecakeisalie on 19 Nov 2010, 11:18, edited 1 time in total.
Image

The right man in the wrong place can make all the difference in the world
- G-Man


Image
User avatar
bsheep
Soldier First Class
Soldier First Class
Posts: 1
Joined: 06 Oct 2010, 12:23
Has thanked: 1 time

Re: How to install C/C++ compiler in Ubuntu

Post by bsheep »

Good tutorial,
thanks for taking the time to share the knowledge. I am also a new linux user(ubuntu). peace
Perfecting - My Skill
Ftw_juhi10
Banned
Banned
Posts: 153
Joined: 14 Nov 2010, 07:30

Re: How to install C/C++ compiler in Ubuntu

Post by Ftw_juhi10 »

this does not have anything to do with microsoft framework 2.0 c++ :book:
Image
User avatar
thecakeisalie
Corporal
Corporal
Posts: 42
Joined: 20 Sep 2010, 22:56
Has thanked: 8 times
Been thanked: 4 times

Re: How to install C/C++ compiler in Ubuntu

Post by thecakeisalie »

Ftw_juhi10 wrote:this does not have anything to do with microsoft framework 2.0 c++ :book:
That's because this is in Ubuntu Linux
Image

The right man in the wrong place can make all the difference in the world
- G-Man


Image
User avatar
WitchBitch
Premium Uploader
Premium Uploader
Posts: 1735
Joined: 22 Jan 2010, 20:41
Location: South of the Mason Dixon, living the good life!

Re: How to install C/C++ compiler in Ubuntu

Post by WitchBitch »

Ftw_juhi10 wrote:this does not have anything to do with microsoft framework 2.0 c++ :book:
points you to the title of the post: How to install C/C++ compiler in Ubuntu
Post Reply

Return to “Programming/Web Building Chat & Support”