I shifted to Ubuntu 10.10 now I am facing problem to have C/C++ compiler. What are the possible ways so that I can use C/C++ compiler using all the libraries (like graphic, math, conio, stdlib, etc) as in Microsoft Windows creating executable file?
8 Answers
Ubuntu provides the standard Gnu Compiler Collection in the repositories.
You can install the Gnu C Compiler gcc
as well as the Gnu C++ compiler g++
with the following command:
sudo apt-get install gcc g++
You'll probably also want to install libc6-dev
(which includes the C standard library) and libstdc++6-4.5-dev
(which includes the standard C++ libraries).
If you're looking for something comparable to Microsoft's Visual C++ compiler, try taking a look at Qt - specifically Qt Creator
. It's a full-fledged IDE with a visual form designer, code-editor, and debugger.


Edit:
Now that it's clear what you mean by "perfectly as in Microsoft windows?", then Qt Creator (which I mentioned above) will be perfect for your needs. You won't need to use the console to compile your applications and the Qt framework is easy to learn and use.
There's a great tutorial for getting started with Qt here.
- 32,495
The below is (1) a simple hello-world program (2) compiled (3) made executable (4) executed. If you don't have the compiler, install gcc and g++ using the software install gui, or by running this command: sudo apt-get install gcc g++
jake@daedalus:~/playground$ cat hello.cc
// 'Hello World!' program
#include <iostream>
int main()
{
std::cout << "Hello World!" << std::endl;
return 0;
}
jake@daedalus:~/playground$ g++ hello.cc -o hello
jake@daedalus:~/playground$ chmod +x hello
jake@daedalus:~/playground$ ./hello
Hello World!
jake@daedalus:~/playground$
- 32,005
You could install the c++ compiler via terminal.
sudo apt-get install build-essential
To write your code there a lot of editors like Gedit (installed by default) or Emacs. If you need an Integrated development environment, you could use Anjuta for example.
sudo apt-get install anjuta anjuta-extras
- 14,533
It's present in all Linux/Unix distributions.
Usage:
gcc hello.c
That's the compiler, but if your question is actually directed towards an IDE, then there are a couple I could recommend:
...and the list goes on...
- 4,315
gcc(GNU Compiler Collection) is one of the most widely used C compilers. Ubuntu uses gcc and is installed by default when you install it on your system. Type gcc <filename> and g++ filename on the terminal to compile C and C++ programs respectively.
- 28,567
Generally, Ubuntu comes with C and C++ compiler. If you have specific requirement for some compiler then you can find and install it. If not available you can install by doing this,
sudo apt-get install build-essential
As for writing codes, there are different IDEs available. The one that I use is Eclipse IDE for C,C++ developer http://www.eclipse.org/downloads/packages/eclipse-ide-cc-developers/junor. If you use IDEs then IDEs will take care of compiling program for you through their GUI but you can also build a code from command line as mentioned in detailed over here http://www.wikihow.com/Compile-a-C/C%2B%2B-Program-in-Ubuntu. Eclipse will also make your life easier when it comes to debugging your code.
Regarding your question on how to open My Computer? You will have to tell me which version of ubuntu you are using and which desktop environment?
For battery do this,
right-click on the status bar (generally on top) -> add to pannel I have added "Indicator applet complete" and then you should have battery indicator.
- 123
- 5
You can write your program in many ways .
If you like terminal text editors then vim and nano are there . If you like GUI text editors gedit is enough for basic users .
so i hope you know how to write a program . For example with Gedit . you can find it by typing as gedit in your unity dash which can activate by pressing Super key on your keyboard .
after opening it , type your program there and save it where you want .
Actually you should have a package named as build-essential to run your C/C++ programs succesfully . if you not installed it then you can with
sudo apt-get install build-essential
from your terminal . as you said you are a basic Ubuntu users and of course new to Ubuntu, you can get your terminal by typing as terminal in your Unity dash as i suggested above .
After saving your program to run it you have to follow these intructions to RUN it .
g++ /path/to/file_name.cpp -o <give some name >
./<give some name >
.hope that helps.
- 105,327
- 107
- 262
- 331
