Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
    
Please edit your question to explain what you mean by "perfectly as in Microsoft windows". –  djeikyb Mar 19 '11 at 4:51
    
Perhaps he means a compiler that creates Win32/64 executables. –  Nathan Osman Mar 19 '11 at 4:52
add comment

7 Answers

up vote 17 down vote accepted

Ubuntu provides the standard Gnu Compiler Collection in the repositories.

You can install the Gnu C Compiler gcc Install gcc as well as the Gnu C++ compiler g++ Install g++ with the following command:

sudo apt-get install gcc g++

You'll probably also want to install libc6-dev Install libc6-dev (which includes the C standard library) and libstdc++6-4.5-dev Install 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 Install qtcreator. It's a full-fledged IDE with a visual form designer, code-editor, and debugger.

enter image description here

enter image description here


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.

share|improve this answer
    
"Perfectly as in microsoft" tends to mean as i can be able to code a bit deeper using graphics and other libraries. i find it troublesome using from terminal using text editor (gedit). –  nebula Mar 19 '11 at 5:11
    
@aneal: I've edited my answer. –  Nathan Osman Mar 19 '11 at 5:17
    
thanks. i will try using that one. lets c if this is the one i am searching for . –  nebula Mar 19 '11 at 5:23
add comment

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$
share|improve this answer
add comment

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

See: How to Compile a C/C++ Program on Ubuntu Linux

German list with IDEs

share|improve this answer
    
i wrote 'sudo apt -get install buid-essential' in the terminal. but i get a error: –  Khurram Usman Sep 8 '12 at 7:16
    
sudo : apt : command not found –  Khurram Usman Sep 8 '12 at 7:17
    
Remove the space after 'apt'. –  BuZZ-dEE Sep 8 '12 at 7:20
    
ok....someting is being installed –  Khurram Usman Sep 8 '12 at 7:26
    
i think it worked....thanks a lot –  Khurram Usman Sep 8 '12 at 7:27
show 1 more comment

GNU's gcc

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:

QtCreator

Anjunta

Eclipse for C/C++

...and the list goes on...

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
    
well i installed ubuntu 12.o4. its default so must be unity. thats waht i read on the internet. –  Khurram Usman Sep 8 '12 at 7:08
    
also how am i supposed to check the battery charge? –  Khurram Usman Sep 8 '12 at 7:08
    
I have updated answer for battery. –  VendettaDroid Sep 8 '12 at 7:13
    
If you find the answer helpful then I suggest to mark it as correct. –  VendettaDroid Sep 8 '12 at 7:14
    
when i right-click on the top bar nothing happens,,,no drop down menu opens up. on the extreme right there are icons for wifi BT time and settings. when i click on them specific menus for them open up but i cant see anything like "indicator applet complete" –  Khurram Usman Sep 8 '12 at 7:24
show 3 more comments

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.