How could I begin C++ programming on Ubuntu?
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?
Solution 1:
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
Solution 2:
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++.
Solution 3:
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
sudo apt-get install codeblocks
in the terminal.
Solution 4:
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
- If you want to write a C++ application with a GUI, you can use Qt Creator
Solution 5:
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.