How to install C/C++ compiler in Ubuntu
Posted: 19 Nov 2010, 09:14
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:
You may or may not be prompted to type in your password
The install process will then start:

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:
(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:

You can copy this code if you like:
Now to compile your program we must type:
(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:
Once all errors have been corrected you can now run your program by typing:
Depending on your program you will get some output in the terminal:

I hope that helps, now go get your programming on.
(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
The install process will then start:
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
A text editor will then open up like so and you can then type in you program. Save your program when done:
You can copy this code if you like:
Code: Select all
#include <iostream>
using namespace std;
int main()
{
cout << "Hello world!" << endl;
return 0;
}
Code: Select all
g++ <name of your program>.cpp -o test
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:
Once all errors have been corrected you can now run your program by typing:
Code: Select all
./test
I hope that helps, now go get your programming on.