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 recently switched to Ubuntu from Windows 7. I was previously learning C++ with Microsoft's IDE, Visual Studio.

  • How would I go about programming C++ on Ubuntu, preferably with an IDE?
share|improve this question
    
possible duplicate of Can I use a C/C++ compiler?? –  Nathan Osman Apr 22 '11 at 23:39
    
related question -> askubuntu.com/questions/8136/c-programing-suites-ides –  hhlp Jun 4 '11 at 8:36
    
[here][1] is a list of ide chose one and start programming [1]: askubuntu.com/questions/8136/c-programing-suites-ides –  Tachyons Mar 3 '12 at 11:17
add comment

5 Answers

You have the standard gcc that comes with Ubuntu. Just ALT+F2 and type gnome-terminal or press CTRL+ALT+T to start a console.

To start programming in the console, just type nano test.c; that way you start working on your first test.c file. Try this:

#include <stdio.h>
int main ()
{
printf("Hello AskUbuntu!");
}

then just press CTRL+X and press Y, then ENTER to save and close.

Compile this test.c file using gcc by typing: gcc test.c -o mytest, which will create a file called mytest (which is executable by typing ./mytest) using the code from test.c.

The same can be said for C++ code. It works the same way as gcc: Compiling a test.cpp file using g++ by typing: g++ test.cpp -o mytest, which will create a file called mytest (which is executable by typing ./mytest) using the code from test.cpp.

This is one way.

Another way I recommend is using Code::Blocks which has been known to work since I have tested it (Ubuntu 8.04, 8.10, 9.04, 9.10, 10.04 and 10.10). Works right out the box, no errors, no nothing. The one I have used so far was Code::Blocks 8.02 but 10.05 came out a couple of months ago and it looks good.

You can install it by running sudo apt-get install codeblocks.

The last method I recommend is Aptana, which is a complete GUI IDE system. Aptana is very complex and will certainly resolve any doubt you have with its complete help system and autocomplete, autohelp way of working. Aptana is much better than the IDE from Microsoft let me tell you right now. Already worked on both for some time now and I will not leave Aptana for big works.

I will leave here some links so you can test:

APTANA - http://www.aptana.com/
CODEBLOCKS - http://www.codeblocks.org/
New Version of C - http://en.wikipedia.org/wiki/C1X
New Version of C++ - http://en.wikipedia.org/wiki/C%2B%2B0x

share|improve this answer
    
I know this is not related to the question. But the 1st part of your answer got me excited :P Do you know how to do the same thing like gcc test.c but for c++ programs ?? Thanks –  Suhaib Sep 16 '12 at 2:29
    
Oh ok the 2nd answer somehow answered my question above :) –  Suhaib Sep 16 '12 at 2:32
    
@Suhaib I "bit" too late but I added the C++ command which is g++. Works the same way. –  Luis Alvarado Apr 6 at 21:16
add comment

You would start with an editor with syntax highlighting, like gedit, scite, emacs, vi or something else.

You would then learn to compile by hand, what an include-path is, what a library-path is, how to switch warnings on and off, how to build .o-files, libraries (.so), executables, and how to build makefiles.

Then you would switch to an IDE, because now you would know what to configure to what values. It's harder if you don't know what, and don't know where. I don't use C++ anymore, so I only may say that from hearsay, Code::Blocks has some good reputation.

Whether it is useful as a visual GUI-Builder I don't know - it isn't even clear from your question, whether you're looking for such a thing.

As Olcay pointed out in the comments, you need to install c++ tools (compiler, linker and so on) for c++ - maybe some dev-packages (development) too.

sudo apt-get install g++

It's not a typo, it is g++ for gnu-c++.

share|improve this answer
2  
I agree with user unknown. It is the best practice to start with gedit like text editor and compiling on console. After you gain experience enough you can try Netbeans or Eclipse IDE. They are very famous and well sported IDEs. In Netbeans you have to install C++ plugin via tools->plugins section. –  Olcay Ertaş Apr 22 '11 at 22:49
3  
Also Ubuntu doesn't come a C++ compiler preinstalled. You have to install it via synaptic package manager or by typing on console: "sudo apt-get install g++" –  Olcay Ertaş Apr 22 '11 at 22:59
add comment

The two most popular IDEs (If you go by reviews on the software centre) are Code::Blocks and Geany. They aren't as feature packed as Visual Studio though.

To install them you can either search on the software centre for them or stick

sudo apt-get install geany

enter image description here

sudo apt-get install codeblocks

enter image description here

in the terminal.

share|improve this answer
add comment

Depending on what you want to do, you might want to use:

  • For general-purpose, non-GUI-related C++ development, you can use Eclipse and the CDT plugin

enter image description here

  • If you want to write a C++ application with a GUI, you can use Qt Creator

enter image description here

share|improve this answer
add comment

I recommend you to use QtCreator or NetBeans - you should try them and you will see that these 2 IDE's are the best for C++ development.
Geany, Aptana(which is actually intended for Web Development) and Codeblocks are not good when you try them all, I assure you.
P.S: Don't listen to guys that tell you that you are not a good programmer if you write programms in IDE's, that's just plain stupid and childish(when they grow up they won't think like this any more). The IDE's don't write the code for you...
To add, even some Linux Kernel developers switched to Qt Creator. Valve and a lot of other big names in the industry use Qt Creator for C and/or C++ development on Linux.

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.