Wednesday 23 September 2009

Installing Code::Blocks c/c++ IDE on Ubuntu 9.04

Visit first the Code:.Blocks' website: http://www.codeblocks.org  and define Code::Blocks...


Picture-1

Installation on Ubuntu 9.04

Update package index first
$ sudo aptitude update

Install required packages
$ sudo aptitude install codeblocks codeblocks-contrib

For code development, you'll also need some additional packages. Run
$ sudo aptitude install build-essential gdb subversion

$ sudo aptitude install automake autoconf libtool

$ sudo aptitude install libgtk2.0-dev libxmu-dev libxxf86vm-dev

These package are for programming with the wxWidgets GUI toolkit. Code::blocks itself is a pure wxWidgets product.
$ sudo aptitude install libwxbase2.8-dev wx2.8-headers libwxgtk2.8-dev wx-common
------------------------------

Then start the codeblocks IDE from the Application -> Programming menu or type:
$ codeblocks

The first launch will ask the compiler name. The default c/c++ compiler in Linux is "GNU GCC compiler".
Select it. See picture:
 Select compiler
------------------------------
Below are some important notes. Especially read the notes 1- 5.
Use the (glut) freeglut library to develope portable OpenGL applications. Read note 1.
Code::Blocks has a GLUT project wizard. Use it to create your first OpenGL project. Build & run.

Some important notes.

Alguns comentários importantes.

[ Note 1 ]
If you want to develope OpenGL (glut...) applications, install FreeGlut first :-)

Click this link... or type the command manually.

$ sudo aptitude install freeglut3 freeglut3-dev 

Ceate a new project and select the "GLUT project" in the project wizard.
An important tip: Say: /usr when it asks the "Please, Select GLUT's location:".
See picture GLUT's location
Read also the Note 5) below.


[ Note 2 ]
   If you want to develope GLFW applications, install GLFW first ( http://glfw.sourceforge.net/ )  
   Read also this posting...   
 The Ubuntu's freeglut library is more up-to-date than GLFW.


[ Note 3 ], c-cpp-reference:
Do not forget to install the "c-cpp-reference" manuals.  Run this command:
$ sudo aptitude install c-cpp-reference

OR use your Synaptic Package Manager and get the package. It will put some help files in the /usr/share/doc/c-cpp-reference/ directory.
Start Firefox and point it to /usr/share/doc/c-cpp-reference/index.html

Also these C/C++ sites are very helpful:
http://www.cppreference.com
+
http://www.cplusplus.com
+
LinuxTutorialC++.html  +  Informit.com's book..

+ The ultimate collection of C++ tutorials
http://ubuntuforums.org/showthread.php?t=333867#2  and C++ wikibook...

+ STL (Standard Template Library) guide
http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html   (couple of simple STL samples test-std1.cpp and test-std2.cpp )


[ Note 4 ],



[ Note 5 ], Important GLUT / OpenGL guides:
Define OpenGL...   Homepage...

Read the note 1) first, then study

Redbook.html   Redbook....   ( direct link... )

Bluebook.html   ( direct link... )

http://www.opengl.org/code/category/C19/
http://nehe.gamedev.net  ( example: how to run the lessons...  on Linux ! )
http://ubuntuforums.org/showthread.php?t=333867#8   Especially good source of programming guides !
http://www.gamedev.net  
http://www.glprogramming.com
http://ubuntu-gamedev.wikispaces.com  ( Ubuntu games )
http://www.glchronicles.mccolm.org (GL Chronicles)

MIT computer graphics (pdf)...

http://www.libsdl.org  Simple Direct Media Layer (Excellent 2D library. Has also OpenGL support )
http://lazyfoo.net/SDL_tutorials/index.php   (....)
or try
http://g2.sourceforge.net/
---
GLUI = OpenGL based GUI library (buttons, edit boxes, list boxes etc...)
http://glui.sourceforge.net

FTGL = Render text (fonts) in OpenGL
http://homepages.paradise.net.nz/henryj/code/#FTGL

Animated OpenGL graphical UI, also to be used in GNOME 3.0 and GTK 3 !
http://clutter-project.org

OpenAL sound
http://www.openal.org

Ubuntu gamers' corner
http://ubuntu-gamedev.wikispaces.com/


[ Note 6 ], wxWidgets examples !
Define wxWidgets...   Homepage...

WxWidgets is a multi platform GUI toolkit.

First, install the wx2.8-examples package
$ sudo aptitude install wx2.8-examples

The package puts the examples into /usr/share/doc/wx2.8-examples/examples/ directory. It's a compressed tar-ball which you have to unpack/untar.

Run the "unpack_examples.sh" script (in the same directory) to unpack the samples to your $HOME directory. 
For example, run:
$ /usr/share/doc/wx2.8-examples/examples/unpack_examples.sh   $HOME/wxwidgets2.8

And it will unpack & put the samples into your $HOME/wxwidgets2.8/samples/ folder.

You can now compile and run the examples directly from the command line.
The compilaton requires wxWidgets' development headers and libraries. You will need these packages; libwxbase2.8-dev  wx2.8-headers  libwxgtk2.8-dev

As an example let's compile the /popup sample code. First, move to the samples/popup/ directory
$ cd $HOME/wxwidgets2.8/samples/popup/

Compile the project.
$ make

Run it 
$ ./popup
./  means the current directory. Yu must include it, otherwise the shell will not find the program, because by default, the current directory is NOT in the $PATH.
$ echo $PATH

Now, try to compile and run the other wxWidgets examples as well.

Study also the wxWidgets' documentation package wx2.8-doc.
$ aptitude search wx2.8-doc
wx2.8-doc - wxWidgets Cross-platform C++ GUI toolkit (documentation)

Install it and list the documentation (html) files
$ dpkg -L wx2.8-doc
$ dpkg -L wx2.8-doc | grep index
And then open the index.html in Firefox.

Of course, the documentation is available online too...
+
read http://zetcode.com/tutorials/wxwidgetstutorial  and http://en.wikibooks.org/wiki/...


[ Note 7 ], Necessary packages to develope SDL-applications.
Define SDL...   Homepage...

SDL stands for Simple DirectMedia Layer...
It's a framework to greate portable 2D graphics applications. It also supports OpenGL.

First, list all packages that belong to the SDL family.
$ aptitude search libsdl | grep dev
The "-dev" packages contain the header (include) files and dynamic libraries for app development. You'll need them.

Install at least these basic packages. These give you a good start.
$ sudo aptitude install libsdl1.2-dev  libsdl-image1.2-dev  libsdl-sound1.2-dev  libsdl-mixer1.2-dev
However, the most basic apps need only the "libsdl1.2-dev".

Then create a basic SDL-application via the Code::Blocks' project wizard (select SDL project).
SDL applications

Note: The SDL's sound, image and mixer functions have their own libraries and include files which you must add to your project.
SDL applications
And add these includes to your code:
#include
#include
#include

Additional information:
This command will list the installed SDL related packages
$ dpkg -l | grep libsdl

This command will list the installed SDL related libraries
$ ls -l  /usr/lib/libSDL*so

This command will list the available include files (most of them are included through the SDL.h)
$ ls -l /usr/include/SDL/*

This command (already in your project's build options) finds the library PATH, library name and the include PATH + possible debug options.
All well done libraries have this xxx-config thing.
$ sdl-config --cflags --libs

See also SDL_tutorials...gamedev.net/SDL  and  cone3d/SDL
Other 2D/3D frameworks... (incl. a link to panda3d)


[ Note 8 ], Make beautiful graphics with Cairo Graphics
Define Cairo graphics...    Homepage...

http://cairographics.org/samples/ 

Cairo tutorial...

MacSlow’s Cairo-Clock (a good example)
http://macslow.thepimp.net/?page_id=23

Study also: OpenVG...


[ Note 9 ]
, Gallium 3D, a new superior graphics engine for Unix/Linux
Define Gallium 3D...   Homepage...

Gallium 3D introduction...

Study also: http://zrusin.blogspot.com and http://aseigo.blogspot.com
+ there's some momentum to put Clutter... with its advanced graphics to the upcoming GNOME 3.0. Really nice.


[ Note 10 ]
, Programming with the Boost c++ library
Define Boost C++...    Homepage...

Study:  http://ubuntuforums.org/#post5164645

Boost.org


[ Note 11 ]
, Other important programming resources:  http://www.futuredesktop.org/opportunities.html
Kernel, driver and module programmer's heaven: http://www.futuredesktop.org/kernel.html



[ Note 12 ], Essential manual pages... that we developers often forget to install and use.

What manual pages does Ubuntu (or any other distro) offer?
$ aptitude search manpages
...
manpages - Manual pages about using a GNU/Linux system
manpages-dev - Manual pages about using GNU/Linux for development
manpages-posix - Manual pages about using POSIX system
manpages-posix-dev - Manual pages about using a POSIX system for development

Install all manpages*dev packages
$ sudo aptitude install manpages-dev manpages-posix-dev

Note:  This command vill tell you what manual sections (1 - 8 ) the package covers.
$ aptitude show manpages-posix-dev

Now search help:
$ man 3 fprintf
$ man sqrt
$ man pthread_create
$ man sem_init

$ man 3 socket
$ man 7 pthreads
$ man 7 sem_overview

Use also whatis and apropos commands (eg. to reveal the section number)
$ whatis pthread_create

$ apropos pthread_create
$ apropos pthread


[ Note 13 ], "How to become a real hacker" by Eric S. Raymond, updated 2008 version.
http://www.catb.org/~esr/faqs/hacker-howto.html


[ Note 14 ], A tip for zooming text in Code::Blocks IDE.
Press CNTR +  NUMPAD + or NUMPAD - keys to zoom the text.
NUMPAD +/- are tangents on the numerical keypad.


[ Note 15 ], Make your machine talk. YES TALK !
Define TTS, Text To Speech...

Read: http://ubuntuforums.org/showthread.php?t=291919

Simple examples using espeak:
$ espeak "Hi, Hi Joe. How are you today?"
$ echo "I beg your pardon, could you help me to find this address." | espeak

$ echo "All your base are belong to us. Do you agree?" | espeak -v en-us -p 10 -s 140

Speak french
$ echo "Avez-vous un frère ou une soeur?" |  espeak -v fr

One more example: Speak the "ls" command's manual page, paragraphs NAME, DESCRIPTION and SEE ALSO.
$ zcat /usr/share/man/man1/ls.1.gz | nroff -man | col -b | sed -e '/./{H;$!d;}' -e 'x;/NAME/b' -e '/DESCRIPTION/b' -e '/SEE ALSO/b' -e d | espeak -p 30 -s 135 -l 10 -v en+3

List available voices (languages)
$ espeak --voices
$ man espeak

Define Speech Recognition...
Study the The Julius voice recognition system and PerlBox voice commander
Writing a command and control application with Julius voice recognition...




[ Note 16 ] ,77 useful Linux commands.
http://searchenterpriselinux.techtarget.com/...


[ Note 17 ],
Windows converts, read this: http://ubuntuforums.org/showthread.php?t=554070
All users, read the sticky threads: http://ubuntuforums.org/forumdisplay.php?f=39


[ Note 18 ],
Learn by studying the existing source code of applications in the Ubuntu distribution.
A real world example: How do I implement a code that can distinguish between real files and file links (symbolic and hard links)?
Answer: Study the source code of the "readlink" command.

But first, what package the readlink belongs to?
$ apt-cache search readlink
coreutils - it is. The GNU core utilities package.

[ Note: You must activate the source code repository in the Software Sources dialog. You will find it in the Administration menu. Activate or add the deb-src lines.
Refresh the package list in your pc (sudo apt-get update) ], then

Apt-get the source. 
$ apt-get source coreutils
$ cd coreutils-6.10

Locate the "readlink" function and all places it's been called from
$ grep -R readlink *

And study the code ;-)

I took this example from Ubuntuforums.org, post 5041297...
-------------------

A second example.
I want to make some improvements to the GNOME's Disk-Mounter applet. It's an applet you have on the desktop panel.
Where's the source? Some digging reveals that the package name is "gnome-applets".

Get the source.
$ mkdir -p $HOME/code &&  cd $HOME/code
$ apt-get source gnome-applets

Use build-dep to install dependencies so we can compile the code.
$ sudo apt-get build-dep gnome-applets

$ cd gnome-applets-2.26*

Configure and compile with the normal mantra; ./configure && make.
Install with sudo make install.

The code of the Disk Mounter is in
$ cd drivemount

Make your changes and type "make" to recompile it.
Type "sudo make install" to install it.



[ Note 19 ]
, I want to compile program XX from source, but it has too many dependencies.

Study the above note (Note 18).
Use build-dep to install *-dev files and dependencies (if the repo has a package for it).

$ sudo apt-get build-dep XX

Then compile XX from source.



[ Note 20 ]
, Ubuntu development and MOTU videos

Learning MOTU: Patching and packaging...  (altern. url...

Ubuntu developers...  Other MOTU videos...

+ Read the Debian maintainer's guide...



[ Note 21]
,
Some really good music for a lonely developer and programmer: Aavepyörä's Album Goddess Guerrilla.
Rhythmbox Media Player can search and download music directly from Magnatune... and Jamendo...

Music

3 comments:

ofer_brown said...

10X alot !
u r my man !

just had a trouble to start sdl with codeblocks..

hope to read and get the help i need..

i'll check it out later.

magnesium said...

I have heard about the Visual C++ that People make fewer mistakes in consistent environments, Programmers can go into any code and figure out what's going on, People new to C++ are spared the need to develop a personal style and defend it to the death, People new to C++ are spared making the same mistakes over and over again, Programmers have a common enemy.

rooparam said...

@magnesium : what is the joy of programming if u can't read the code of other people. I think thats why FSF and opensource exist. they make programmers happy by giving them eternal joy. by using visual c++, we are restricted to windows platform. i think for code completion, netbeans is the best IDE for windows, macosx, linux. but codeblocks is really nice for programming on linux too.

Best Regards,
Rooparam Bhakar