Showing posts with label C on Linux. Show all posts
Showing posts with label C on Linux. Show all posts

Sunday, December 30, 2012

Using OpenCV in GTK sample program "Inverting an image on Image Processing"

In this article I want to show you How we can use the OpenCV on GTK (GIMP toolkit) on fedora.Although GTK+ is a GNU project like the GMP, it is released under the terms of the more liberal LGPL(lesser general public license) that permits software (including closed source proprietary software) to be written using GTK+ without payment of fees, royalties, or other restirictions. The freedom offered by the GTK+ license is in contrast to its competitor QT(you must instead purchase a commercial Qt license in that case).
This program is compile using gcc compiler on fedora. At first you need to install the gtk and gnome on your machine.
In fedra that use RPM packages, you should have at least install the following RPM package.
$  su

$  yum install gtk2
$  yum install gtk2-devel
$  yum install gtk2-engines
$  yum install libgnome-
$  yum install libgnome-devel
$  yum install libgnomeui
$  yum install libgnomeui-devel

Now its time to install OpenCV package.

Using semaphore to synchronize the multiple thread using c on linux/fedora

Semaphore is a new type of variable introduced by E. W. Dijkstra. You may learn about semaphores in university. It is used to solve the Producer-Consumer Problem in Operation system design which I have learn in books "Modern Operating Systems " (second edition) by Andrew S. Tanenbaum. In that books the algorithm for semaphore is clearly defined and easy to understand. But I was always curious about that "Does this type of problem occur on our program?" rather than operating system design and "Where can I use it?". When I begin to learn linux programming I found the semaphore function under <semaphore.h> header and example program where semaphore is used to synchronize the thread.
In this article we look at the simplest type of semaphore, a binary semaphore that takes only values 0 or 1. There is also a more general semaphore that takes a wider range of values. Normally, semaphores are used to protect a piece of code so that only one thread of execution can run it at any one time.The semaphore functions do not start with pthread_,as most thread-specific functions do,but with sem_. Four basic semaphore functions are used in threads. They are all quite simple.

Friday, December 28, 2012

Threads Program using c on linux/fedora


This program creates a single extra thread, shows that it is sharing variables with the original thread, and gets the new thread to return a result to the original thread. Multithreaded programs don't get much simpler than this.
Lets look the function which create the thread. pthread_create creates a new thread,much as fork creates a new process.
#include<pthread.h>
int pthread_create(pthread_t *thread, pthread_attr_t *attr, void(*start_routine)(void *), void *arg);
The first argument is a pointer to pthread_t . When a thread is created, an identifier is written to the memory location to which this variable points.This identifier enables you to refer to the thread . The next argument sets the thread attributes. You do not usually need any special attributes, and you can simply pass NULL as this argument. Later is the chapter you will see how to use these attributes. The final two arguments tell the thread the function that it is to start executing and the arguments that are to be passed to this function.

Saturday, December 1, 2012

Creating Static Libraries using c on linux Fedora.

You have seen the library file  ".lib" extension on Windows and a ".a" on LINUX/UNIX.If you are unknown about what are they and how to create them then you will get answer here.
These are Static Library files, also known as archives, which are simply a collection of ordinary object files. It is a set of routines, external functions and variables which are resolved in a caller at compile-time and copied into a target application by a compiler, linker, or binder, producing an object file and a stand-alone executable. Simply we can say it permit users to link to programs without having to recompile its code, saving recompilation time.
There are several advantages of static libraries:
1.The most significant is that the application can be certain that all its
    libraries are present and that they are the correct version. This avoids
    dependency problems.
2. Result in a significant performance improvement.
3. Can be shared between many applications leading to space savings.
4. It also allows the library to be updated to fix bugs and security flaws
    without updating the applications that use the library.

Saturday, November 17, 2012

Start learning C on Linux (Fedora)

We students learn c on windows . We create the executable file (.exe) using turbo c or gcc compiler that runs only in windows machine. Have you tried the c on Linux and generating executable file for Linux? Not yet then follow this article.
In this article you learn how to:
1. Install  linux (e.g fedora or ubuntu)
2. Install  gcc compiler in fedora
3. Compile the c program using gcc.
You will also understand what are the executable file in Linux.