Page 1 of 1

How to install C/C++ compiler in Ubuntu

Posted: 19 Nov 2010, 09:14
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.

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

Posted: 19 Nov 2010, 09:20
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 :)

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

Posted: 19 Nov 2010, 11:17
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:

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

Posted: 19 Nov 2010, 11:20
by bsheep
Good tutorial,
thanks for taking the time to share the knowledge. I am also a new linux user(ubuntu). peace

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

Posted: 27 Nov 2010, 23:05
by Ftw_juhi10
this does not have anything to do with microsoft framework 2.0 c++ :book:

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

Posted: 03 Dec 2010, 15:41
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

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

Posted: 03 Dec 2010, 18:47
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