How to Install C and C++ Compilers in Ubuntu and testing your first C and C++ Program
Posted by admin on May 4th, 2008
Email This Post
Install C and C++ Compilers in Ubuntu
sudo aptitude install build-essential
This will install all the required packages for C and C++ compilers
Testing C and C++ Programs
Compiling Your first C Programs
Now you need to open first.c file
sudo gedit first.c
add the following lines save and exit the file
Firstly compile the code using the following command
cc -c first.c
that would produce an object file you may need to add to the library.
then create an executable using the following command
cc -o first first.c
Now run this executable using the following command
./first
Output should show as follows
Hello, world
Compiling your first C++ program
If you want to run c++ program follow this procedure
g++ is the compiler that you must use.
you should use a .cpp file extension rather than a .c one
You need to create a file
sudo gedit first.cpp
add the following lines save and exit the file
Run your C++ Program using the following command
g++ first.cpp -o test
./test
Output should show as follows
Hello World!
If you want to be notified the next time we write something please subscribe to our RSS feed.Thanks for Visiting!


May 4th, 2008 at 1:34 pm
There is no need for being root, when editing your source code. So, call gedit WITHOUT sudo.
Cheers,
Martin
May 4th, 2008 at 9:38 pm
> sudo gedit
omg you fail
May 4th, 2008 at 9:54 pm
karl@ubuntu:~$ g++ first.cpp -o test
first.cpp:5: error: stray ‘\357’ in program
first.cpp:5: error: stray ‘\243’ in program
first.cpp:5: error: stray ‘\271’ in program
first.cpp: In function ‘int main()’:
first.cpp:4: error: expected primary-expression before ‘|’ token
first.cpp:5: error: ‘end’ is not a member of ‘std’
karl@ubuntu:~$ ./test
bash: ./test: No such file or directory
May 4th, 2008 at 10:03 pm
the c++ didn’t work for me
karl@ubuntu:~$ g++ first.cpp -o test
first.cpp:5: error: stray ‘\357’ in program
first.cpp:5: error: stray ‘\243’ in program
first.cpp:5: error: stray ‘\271’ in program
first.cpp: In function ‘int main()’:
first.cpp:4: error: expected primary-expression before ‘|’ token
first.cpp:5: error: ‘end’ is not a member of ‘std’
karl@ubuntu:~$ ./test
bash: ./test: No such file or directory
May 5th, 2008 at 3:14 am
Never call your test program “test”. There is already a system utility called “test”. If you run “test” instead of “./test” you’ll have endless hours of fun:-)
“”"first.cpp:5: error: stray ‘\357’ in program”"”
looks like non-ASCII characters in your source file. Did you use a wordprocessor to edit it by any chance?
“”"first.cpp:5: error: ‘end’ is not a member of ‘std’”"”
it’s “endl”, not “end”. Note the trailing “eL” for end-line.
May 5th, 2008 at 11:02 am
It would be better if you use gcc compiler instead of cc.
May 6th, 2008 at 10:46 am
Akshar, cc is gcc on *buntu.
May 24th, 2008 at 1:42 am
>sudo gedit
omg you fail
June 7th, 2008 at 2:58 pm
Thanks a lot for this tutorial =)
July 1st, 2008 at 6:36 pm
now it worked using this:
#include
using namespace std;
int main()
{
cout<<”HEY, you, I’m alive! Oh, and Hello World!\n”;
cin.get();
}
July 1st, 2008 at 6:38 pm
now it worked using this:
#include
using namespace std;
int main()
{
cout<<”HEY, you, I’m alive! Oh, and Hello World!\n”;
cin.get();
}
July 1st, 2008 at 6:42 pm
the word doesn’t appear. is:#include
July 1st, 2008 at 6:44 pm
iostream
July 2nd, 2008 at 2:41 am
Damn. Using Windows compilers, like Borland 3.11 or Builder is more easier… Need more practice, I think.
July 2nd, 2008 at 2:41 am
But hey, thx for man!
July 3rd, 2008 at 5:50 am
I have c program file with make file, How i can run in ubuntu 8.04