I've recently installed Ubuntu 11.10 and along with it the CodeBlocks IDE and I am aware that I have gcc and the std libraries by default.
My questions are:
- Do you you have any tips for a new C++ programmer on Ubuntu?
- Any libraries I should get from the start?
- A really good IDE I'm missing? (YMMV but I prefer to work in IDE's)
- Any programming boons or traps I should be aware of from the start?
On the first steps of programming you should not use IDE because you will better understand what happens backside :) GCC or G++ and stdlib will be sufficient. You also should read about Makefiles, SVN(CVS, GIT), Autotools or CMake to manage your projects. If you want make GUI applications you should learn GTK+ or Qt. If you want real IDE for your needs try Eclipse with C/C++ plugins. Good luck :)
Some tips besides those which are already mentioned:
valgrind --tool=callgrind
and KCacheGrind to see where does your program spend time on execution.QT Creator is a good IDE, that works well also with simple Makefile based projects. Also, as a C++ programmer you should check out Dia and Dia2Code for automatic generation of stubs from UML diagrams.
Since you ask more than one question I will answer each separately.
Do you you have any tips for a new C++ programmer on Ubuntu?
Learn some build system such as CMake or SCons. Although understanding how make and Makefiles work is useful there is a tendency of moving away from make to more high-level tools which also provide configure-like functionality. Make is often used for command-line build, for example with CMake you can generate Makefiles and build your projects using make.
Use a version control system such as git or Mercurial. I also recommend keeping those your projects you care about on some external service like github at least for the purposes of backup.
Pay attention to compiler warnings but keep in mind that warnings only catch a fraction of possible errors. A more complete picture can be obtained using static analysis tools and dynamic analysis tools like Valgrind.
Any libraries I should get from the start?
A really good IDE I'm missing? (YMMV but I prefer to work in IDE's)
Eclipse - for a long time I've been thinking of it as a Java only IDE, but in fact it is an excellent IDE for almost anything (I even wrote my PhD thesis in it using TeXlipse plugin) and C/C++ support is improving all the time. Also CMake can generate Eclipse CDT project files.
Qt Creator - another excellent C++ IDE. It is very fast and has native CMake support
Any programming boons or traps I should be aware of from the start?
You don't need an IDE to code in C or C++ on Ubuntu. You can use a good editor (like
emacs
, which you can configure to suit your needs.).Some few tips for a newbie:
-Wall -Wextra
and perhaps even with-Werror -pedantic-errors
Order of arguments to the compiler (
gcc
org++
) are really important; I recommend:-Wall
,-g
to get debug info,-O
,-flto
etc, or-c
to avoid linking , ...)-I
include-dir and-D
defined-symbol (or-H
to understand which headers get included) etc..hello.c
orworld.cc
else.o
, add them after the source files-L
library-dir (and probably-rdynamic
if your program uses plugins with dlopen(3) ....)-lfoo -lbar
from higher-level libraries likelibfoo.so
to lower-level libraries.-o yourexec
.Always correct your source code till you got no warning at all. Trust the compiler's warnings and error messages.
Learn how to use
make
and to write simpleMakefile
-s; see this example.there are other builders, e.g. http://omake.metaprl.org/ etc
-g
flag to have the compiler produce debugging information; only when you have debugged your program, ask the compiler to optimize (e.g. with-O1
or-O2
), especially before benchmarking.gdb
svn
orgit
(even for a homework assignment). In 2015 I recommend git oversvn
NB
The advices above are not specific to Ubuntu 11.10, they could apply to other Linux distributions and other Ubuntu versions.
Eclipse/CDT runs really well on Ubuntu.