Monday, October 18, 2010

Use Graphical Libray of GTK+ 2.0 in C programs and Complie with GCC / G++.

In ubuntu (10.10, Lucid Lynx), you can use GTK+ graphical libraries along with gcc / g++ to write graphical applications. There are 2 ways to install Gtk+ in ubuntu.

1. Download Source code and install using ./configure, make, make install. You need to ensure that some dependant packages are already installed (pango, cairo, atk, pixman, glib, gdk-pixbuff, etc).

2. Second method is to use the binary (.deb) packages available on Ubuntu repositories.

In order to Install GTK+-2.0 package under ubuntu, you need to install all below packages, which will install all libraries needed for GTK+ to work.

* gir1.0-gtk-2.0_2.20.1-0ubuntu2_i386.deb (543.7 KiB)

* gtk2-engines-pixbuf_2.20.1-0ubuntu2_i386.deb (718.8 KiB)

* gtk2.0-examples_2.20.1-0ubuntu2_i386.deb (977.7 KiB)

* libgail-common_2.20.1-0ubuntu2_i386.deb (442.7 KiB)

* libgail-dbg_2.20.1-0ubuntu2_i386.deb (869.5 KiB)

* libgail-dev_2.20.1-0ubuntu2_i386.deb (333.2 KiB)

* libgail-doc_2.20.1-0ubuntu2_all.deb (333.1 KiB)

* libgail18_2.20.1-0ubuntu2_i386.deb (332.6 KiB)

* libgtk-directfb-2.0-0_2.20.1-0ubuntu2_i386.deb (2.1 MiB)

* libgtk-directfb-2.0-0-udeb_2.20.1-0ubuntu2_i386.udeb (1.8 MiB)

* libgtk-directfb-2.0-dev_2.20.1-0ubuntu2_i386.deb (327.3 KiB)

* libgtk2.0-0_2.20.1-0ubuntu2_i386.deb (2.4 MiB)

* libgtk2.0-0-dbg_2.20.1-0ubuntu2_i386.deb (10.2 MiB)

* libgtk2.0-bin_2.20.1-0ubuntu2_all.deb (328.9 KiB)

* libgtk2.0-common_2.20.1-0ubuntu2_all.deb (706.0 KiB)

* libgtk2.0-dev_2.20.1-0ubuntu2_i386.deb (3.6 MiB)

* libgtk2.0-doc_2.20.1-0ubuntu2_all.deb (3.8 MiB)

Note : The package libgtk-directfb-2.0-0-udeb_2.20.1-0ubuntu2_i386.udeb may fail to install. You may ignore it.

3. Write a simple Program in C (sample given below),


/* This is a callback function. The data arguments are ignored
* in this example. More on callbacks below. */

static void hello( GtkWidget *widget, gpointer data )
   g_print ("Hello World\n");

static gboolean delete_event( GtkWidget *widget, GdkEvent *event, gpointer data )
/* If you return FALSE in the "delete-event" signal handler,
* GTK will emit the "destroy" signal. Returning TRUE means
* you don't want the window to be destroyed.
* This is useful for popping up 'are you sure you want to quit?'
* type dialogs. */

g_print ("delete event occurred\n");

/* Change TRUE to FALSE and the main window will be destroyed with
* a "delete-event". */
return TRUE;

/* Another callback */
static void destroy( GtkWidget *widget, gpointer data )
gtk_main_quit ();

int main( int argc, char *argv[] )
/* GtkWidget is the storage type for widgets */
GtkWidget *window;
GtkWidget *button;

/* This is called in all GTK applications. Arguments are parsed
* from the command line and are returned to the application. */
gtk_init (&argc, &argv);

/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

/* When the window is given the "delete-event" signal (this is given
* by the window manager, usually by the "close" option, or on the
* titlebar), we ask it to call the delete_event () function
* as defined above. The data passed to the callback
* function is NULL and is ignored in the callback function. */
g_signal_connect (window, "delete-event",G_CALLBACK (delete_event), NULL);

/* Here we connect the "destroy" event to a signal handler.
* This event occurs when we call gtk_widget_destroy() on the window,
* or if we return FALSE in the "delete-event" callback. */
g_signal_connect (window, "destroy",G_CALLBACK (destroy), NULL);

/* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER (window), 10);

/* Creates a new button with the label "Hello World". */
button = gtk_button_new_with_label ("Hello World");

/* When the button receives the "clicked" signal, it will call the
* function hello() passing it NULL as its argument. The hello()
* function is defined above. */
g_signal_connect (button, "clicked",G_CALLBACK (hello), NULL);

/* This will cause the window to be destroyed by calling
* gtk_widget_destroy(window) when "clicked". Again, the destroy
* signal could come from here, or the window manager. */
g_signal_connect_swapped (button, "clicked",G_CALLBACK (gtk_widget_destroy), window);

/* This packs the button into the window (a gtk container). */
gtk_container_add (GTK_CONTAINER (window), button);

/* The final step is to display this newly created widget. */
gtk_widget_show (button);

/* and the window */
gtk_widget_show (window);

/* All GTK applications must have a gtk_main(). Control ends here
* and waits for an event to occur (like a key press or
* mouse event). */
gtk_main ();
return 0;
4.Compile using below command,
gcc -Wall -g HellowWorld.c -o HellowWorld `pkg-config --cflags gtk+-2.0` `pkg-config --libs gtk+-2.0`

5.To run the output file, ./HellowWorld

Saturday, October 16, 2010

How to Install Graphics Libraries and use under (Linux) gcc/g++ (graphics.h)

Here are the steps that I used.

  1. In order to include graphics.h header file, you need to install libgraph package.
  2. Search the source code for “libgraph”. Install by using commands,
    make install
  3. Sometimes, you may get error message “configure: error: *** SDL version x.x.x not found!”. You can solve this by installing “apt-get install libsdl1.2-dev”.
  4. Sometimes, you may get error message “configure: cannot find guile-config; is Guile installed?”. You can solve this by installing “sudo apt-get install guile guile-dev”.
  5. Sometimes, you may get error message “SDL_image-x-xx-x not found”. You may install by searching sourcecode “SDL_image” and following commands “./cofigure make make install”.
  6. When I tried to compile a C file, I got error message,
    vksalian@vksalian-laptop:~/Desktop$ gcc vvv.c -o vvv -lSDL -lSDL_image
    In file included from /usr/local/include/grtext.h:26,
    from /usr/local/include/graphics.h:116,
    from vvv.c:8:
    /usr/local/include/SDL/SDL_image.h:28:17: error: SDL.h: No such file or directory
    /usr/local/include/SDL/SDL_image.h:29:25: error: SDL_version.h: No such file or directory
    /usr/local/include/SDL/SDL_image.h:30:24: error: begin_code.h: No such file or directory
    /usr/local/include/SDL/SDL_image.h:134:24: error: close_code.h: No such file or directory
  7. sudo apt-get install libsdl-image1.2-dev freetype, libsdl1.2, libsdl1.2-dev, libsdl-image1.2-dev, and libsdl-image1.2.
  8. Copy header files with command “sudo cp /usr/local/lib/libgraph.* /usr/lib
  9. Then changed the arguiments to compile the C Program and the command looks like (all libraries included),
    gcc -g -Wall -I/usr/include/SDL -I/usr/local/include/SDL -I/usr/local/include -D_GNU_SOURCE=1 -D_REENTRANT -L/usr/lib -lSDL -I/usr/local/include/SDL -lSDL -lSDL_image -I/usr/local/include -lgraph -o vvv vvv.c
  10. Please note the below point.
    `sdl-config –cflags` & `sdl-config –libs` can replaced for -I/usr/include/SDL -I/usr/local/include/SDL -I/usr/local/include -D_GNU_SOURCE=1 -D_REENTRANT -L/usr/lib -lSDL -I/usr/local/include/SDL -lSDL -lSDL_image -I/usr/local/include
  11. Sample C Program I used to test this,
    void main()
    int gd,gm=VGAMAX;
    int a;
    return 0;

  1. You may use the article below (for more details).

        Graphics.h in GNU/Linux By

    Ive read and pondered upon lots of blogs and posts regarding the topics "20xx is the year of the linux desktop" , "linux is not yet ready for the desktop" etc etc.I guess the answer to all such questions is personal in nature. I mean id say "try and find out". I started using a GNU/Linux distribution about 8 months ago. Since then my aim was to do whatever stuff i was doing on XP, on GNU/Linux and maybe find stuff i couldnt do on XP. Thats how i approached/read about GNU/Linux though i later found out that, that approach isn't exactly right, as i was merely "reducing" GNU/Linux to a windows replacement, while its actually a whole another approach to computing.
    Anyways, since i joined engineering if there was one thing i didnt like at all, then it was the "Blue Screen Of Death" or the Turbo C interface. Since s3 i never used Turbo C at home. I've always preferred Visual Studio or Dev C++ over Turbo C. I just didnt like the interface. This dislike of turbo C didnt however hamper my coding functionalities in other IDE's as they always had what i wanted. After moving to GNU/Linux i was able to do the same programs and compile them using G++. But s7 is were the problem starts. Now i gotta "computer graphics" lab which makes extensive use of the "graphics.h" library. I had heard rumours earlier that it wasnt available in all IDE's and to my dismay i found out that it wasnt there in GNU/Linux either. Another problem was that since the functions it included involved direct access to the hardware merely copying the graphics.h header to the library folders wouldnt help. As always google helped. Stumbled upon the blog of a person who was in the same situation as I am and he had found a solution. The answer to my problem was a set of libraries called libgraph which wraps around the SDL API.
    His blog did contain steps to install in debian but it didnt work for me coz of minor hiccups. SO i spent sometime and finally succeeded in getting it to work on my ubuntu feisty install. I just thought i'd post it here so that google drops this in front of another seeker :)

    Step 1: Installing dependencies

    run sudo apt-get install build-essential to make sure you have installed all necessary compiler tools

    Now comes the real achy part. Open synaptic and install the following packages


    You can install them in a single go by adding all the above package names(separated by a black space) to the end of sudo apt-get install Even if it asks you to uninstall some already installed stuff, tell it to proceed. After all this is over. Download this file onto your home folder: libgraph-1.0.1

    Right click on the file u just downloaded and click "Extract here"

    open terminal and navigate into the folder u just extracted the file contents into by running cd libgraph-1.0.1
    Now run the following commands one after the another. Proceed to the next command only if the preceding command executes without any errors.

    sudo make
    make install
    If you get any errors during the "sudo make" step, paste it in the comments section of this post.

    Now technically install is over. Try writing a simple program including graphics.h. Declare the values of gd and gm and call initgraph as follows

    int gd,gm=VGAMAX; gd=DETECT;initgraph(&gd,&gm,NULL);

    and when compiling using g++ add an extra paramter -lgraph
    i.e if you are compiling a program dda.cpp in the terminal u type in

    g++ dda.cpp -o dda.o -lgraph
    And execute the program by runnung ./dda.o

    If on compile it gives u an error that says "could not load shared libraries" or something like that just run the following command and it should fix it

    sudo cp /usr/local/lib/libgraph.* /usr/lib
    I also read somewhere that graphics.h dosen't have ANY practical use in today's world and that its only "use" now is to help students learn to apply different algorithm's they have to study in a paper called "Computer Graphics"

Wednesday, October 13, 2010

Vruksham Software Core Developers.

An enthusiastic team situated in Hanchinal, Kundgol Taluk, Dist. Dharwad have started a Software Development Group for development of customised software solutions for both RPM and DEBIAN linux Operating Systems. The team is known as Vruksham Software Core Developers.

Scope : The main target of the team is to customize the softwares used for VLSI DESIGN and SIMULATION. With the solutions provided at VSCD, one can automate most of the design related stuffs and there by reducing sufficient time and money spent on works.
For example, there is a software (development version) that is capable of automating Magic Layout generation as per the given input data. The layout of any size can be regenerated automatically, several times with no much effort. You can download the package at below links,

The team is headed by Mr. Basavaraj Tambur,  with plenty of knowledge in Python, Perl, TK/TCL, Java, C/C++ scripting.

One more person named Mr. VKSALIAN has knowledge on RPM and DEBIAN packages and basic script knowledge is assisting the team in creating Installer packages for Linux. Presently he is concentrating on Package creation methods and customization of packages.

Basically, the idea for software development came into mind when they found some scope for customization and automation of softwares. Then, with little knowledge they started creating small packages and found success, surprisingly. They continued the work as an entertainment which resulted in technical knowledge development. Soon, they thought of forming a group to develop such softwares, and the result is VSCD.

The present Projects being handled at VSCD are,

1. File converter from .rm to mp3 (all formats) for Linux.
2. Automation for Magic Layouts (VLSI).

Future projects we planned,

1. Decoder package for all formats in single package. (Linux).
2. Karaoke Maker software for Linux (High quality).
3. Simulation program for VLSI designs with flexibility (replacement for ngspice).
4. Mini Linux OS (VSCD Linux).

You may download trial base sample development packages here, below,


Thursday, October 7, 2010

Cheapest Mic-Set, using Ubuntu Linux OS, for conducting seminars and functions.

If you are using a laptop (ASUS LAPTOP in my case) with UBUNTU 9.04 Linux, then you can use the computer to setup a Cheapest MIC-SET that you may need to conduct functions, meetings etc.

What are the things needed ?

1. A small MIC from a Mobile Head Phone..

2. 3mm Audio Jack with paired wires of sufficient length.

3. Any cheap Amplifier / FM set that is available in market for Rs. 300/-.

4. Old PC speakers- 2 Nos.


1. Solder MIC to the cable that connects to the Audio Jack.

2. Insert the audio jack into ASUS eeePc Laptop.

3. Swith on the Laptop.

4. Use Volume Control Panel to switch the MIC ON. Make Volume level high.

5. Connect the audio output to Amplifier.

6. Talk at the MIC and correspondingly adjust the MIC volume.


Advantages :

1. You can save upto Rs. 1000 / day. Because the rented MIC_SET costs around Rs. 1000/ day at our place.

Note : This article is to just show that how differently we can think.