Menu

28 January 2007

Ultimate Fedora core 6 Help !!!!!!!!!

==========================
first install yumex by
$su
then type password then
$yum -y install yumex
==========================
whenever you want to install ,, install by yumex,,, GUI mode of yum..........
path is
Application -> System Tools -> Yum Extender
===========================

  1. ultimate help for core 6
  2. Official Documentation website
  3. Replace the fives with sixes as appropriate. Fedora Core 6 Linux Installation Notes
  4. Unfficial Fedora FAQ
  5. Fedora Core 6 Tips and Tricks
  6. Mauriat Miranda's Personal Fedora Core 6 Installation Guide
  7. Fedora Forum
  8. Fedora Solved
  9. Other places
I Highly recommend to go 6. then 1. then others..........
=======================================
Fedora Live CD

http://download.fedora.redhat.com/pub/fedora/projects/live/FC-6-i386-livecd-1.iso
SHA1SUM: 8771d21af1974492424438cbe42f1bae0161ea96 FC-6-i386-livecd-1.iso

26 January 2007

CREATION OF STATIC AND SHARED LIBRARIES

Linux :
Creating Static Libraries
we have 4 files with us
  • fun1.c => it store code of “add” and “sub” function.
  • fun2.c => it store code of “mul” and “div” function.
  • header.h => it store prototype of “add” , “sub” ,“mul” ,” div” function
  • user_pro.c =>user program that calls the function.
We have some intermediate files
  • fun1.o object code for fun1.c
  • fun2.o object code for fun2.c
  • mylib_sta.a static library made by combining both object file
  • user_pro.o object code for user_pro.c
we have final executable file user_pro_final
  • user_pro_final binary file ( executable file )
coding of each files
=====================================================
fun1.c
-----------------------------------------------------------------------------------------
int add (int a , int b){return a+b;}
int sum (int a , int b){return a-b;}
=====================================================
fun2.c
------------------------------------------------------------------------------------------
int mul (int a , int b){return a*b;}
float div (int a , int b){return ((float)a)/b;}
=====================================================
header.h
-----------------------------------------------------------------------------------------
int add (int a , int b);
int sub (int a , int b);
int mul (int a , int b);
float div (int a , int b);
=====================================================
user_pro.c
------------------------------------------------------------------------------------------
#include"header.h"
#include
main()
{
int a,b;
printf("Enter a: ");
scanf("%d",&a);
printf("Enter b: ");
scanf("%d",&b);
printf("\naddition of a and b is %d: ",add(a,b));
printf("\nsutraction of a and b is %d: ",sub(a,b));
printf("\nmultiplication of a and b is %d: ",mul(a,b));
printf("\ndivide of a and b is %f: ",div(a,b));
return 0;
}
================================================
apply this procedure
$ pwd
/home/student/Narendra/static

step 1 : create object code for all three .c file
$ gcc -c fun1.c fun2.c user_pro.c
$ ls *.o
fun1.o fun2.o user_pro.o
step 2 : create static named mylib_sta.a library from fun1.o and fun2.o
$ ar rcv mylib_sta.a fun1.o fun2.o
a – fun1.o
a – fun2.o
step 3 : create executable file named user_pro_final
$ gcc -o user_pro_final user_pro.o mylib_sta.a
step 4 : execute the user_pro_final
$ ./user_pro_final
Enter a: 45
Enter b: 12
addition of a and b is 57:
subtraction of a and b is 33:
multiplication of a and b is 540:
dividing of a and b is 3.750000:


Creating Shared Libraries
Load time Linking
we will work with some files from previous namely fun1.c fun2.c user_pro.c .
but we will produce mylib_shr.a this time
$ pwd
/home/student/Narendra/shared
step 1 : create object code of all .c files
$ cc -Wall -fPIC -c fun1.c fun2.c user_pro.c
$ ls *.o
fun1.o fun2.o user_pro.o
step 2 : create shared library with fun1.o and fun2.o
$ cc -shared fun1.o fun2.o
$ mv a.out mylib_shr.so
step 3 : linking of shared lib to user code to produce user_pro_final again
$ cc user_pro.o -L. mylib_shr.so -o user_pro_final
step 4 : laod library path
$ LD_LIBRARY_PATH=/home/student/Narendra/shared
$ export LD_LIBRARY_PATH
step 5 : run the executable file
$ ./user_pro_final_exe
Enter a: 45
Enter b: 12
addition of a and b is 57:
subtraction of a and b is 33:
multiplication of a and b is 540:
dividing of a and b is 3.750000:

Lazy Linking
we have to modify the code in main program
====================================
user_pro.c
----------------------------------------------------------------
#include"header.h"
#include
#include
int main()
{
void* funptr;
int (*add)(int a,int b);
int (*sub)(int a,int b);
int (*mul)(int a,int b);
float (*div)(int a,int b);
funptr = dlopen("/home/student/Narendra/dyna/mylib_shr.so", RTLD_LAZY);
if (!funptr)
{
fprintf(stderr, "Error during dlopen(): %s\n", dlerror());
return 1 ;
}
add= dlsym(funptr, "add");
sub= dlsym(funptr, "sub");
mul= dlsym(funptr, "mul");
div= dlsym(funptr, "div");
int a,b;
printf("Enter a: ");
scanf("%d",&a);
printf("Enter b: ");
scanf("%d",&b);
printf("addition of a and b is %d: ",add(a,b));
printf("\nsubtraction of a and b is %d: ",sub(a,b));
printf("\nmultiplication of a and b is %d: ",mul(a,b));
printf("\ndividing of a and b is %f: ",div(a,b));
printf("\n");
dlclose(funptr);
return 0;
}
====================================================
$ pwd
/home/student/Narendra/dyna
step 1 : create object code of all .c files
$ cc -Wall -fPIC -c fun1.c fun2.c user_pro.c
$ ls *.o
fun1.o fun2.o user_pro.o
step 2 : create shared library with fun1.o and fun2.o
$ cc -shared fun1.o fun2.o
$ mv a.out mylib_shr.so
step 3 : create executable file
$ cc user_pro.o -L. mylib_shr.so -o user_pro_final -ldl
step 4 : run the executable file
$ ./user_pro_final
Enter a: 45
Enter b: 12
addition of a and b is 57:
subtraction of a and b is 33:
multiplication of a and b is 540:
dividing of a and b is 3.750000:
========================================================
Windows Environment:
In windows we use VC++ to create the dll. The following process have to be
followed to make the dll.
Creating a Win32 dll:
• Open the New Project Wizard.
• Select Win32 Dynamic-Link Library.
• Name the project as dllfun1.
• In the next screen, select "A dll that exports some symbols" radio button.
• Click Finish. The dll project will be created.
• Now open the file dllfun1.cpp. We can see a function definition for
"DLLASSIGN_API int fndllfunl(void)".
• Replace this function with the code of your library function. Like this you can
define any number of functions in that file.
==========================================================
dllfun1.cpp
---------------------------------------------------------------------------------------------------
// dllfun1.cpp : Defines the entry point for the DLL application.
//
#include "stdafx.h"
#include "dllfun1.h"
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}
DLLFUN1_API int add (int a , int b){return a+b;}
DLLFUN1_API int sub (int a , int b){return a-b;}
// This is the constructor of a class that has been exported.
// see dllfun1.h for the class definition
CDllfun1::CDllfun1()
{
return;
}
==========================================================
• Open the dllfun1..h file and insert the declaration
===================================================
dllfun1.h
--------------------------------------------------------------------------------------
#ifdef DLLFUN1_EXPORTS
#define DLLFUN1_API __declspec(dllexport)
#else
#define DLLFUN1_API __declspec(dllimport)
#endif
// This class is exported from the dllfun1.dll
class DLLFUN1_API CDllfun1 {
public:
CDllfun1(void);
// TODO: add your methods here.
};
DLLFUN1_API int add (int a,int b);
DLLFUN1_API int sub (int a,int b);
====================================================
• Create a new file named "dllfun1.Def" and add the following code in that file.
==========================================
dllfun1.Def
---------------------------------------------------------------------
; dllfun1.def : Declares the module parameters for the DLL. LIBRARY "dllfun1"
DESCRIPTION 'DemoDll Windows Dynamic Link Library'
EXPORTS
; Explicit exports can go here
add PRIVATE
sub PRIVATE
==============================================
• Add this dllfun1.def into the project.
• Build the project.The dll will be created.
• Follow the above steps to create another dll file “dllfun2.dll” that contain function
mul and div1 .
• Store both dll files into C:\mydll folder
Using the dll
This part explains only the dynamic loading using loadlibrary. The following sample
code I have used in a new console application which uses the library functions defined in
dllfun1.dll and dllfun2.dll library.
===============================================
user_pro.cpp
---------------------------------------------------------------------------------------
#include
#include
typedef int (*FunPtrTypeInt)(int a,int b);
FunPtrTypeInt add , sub , mul ;
typedef float (*FunPtrTypeFloat)(int a,int b);
FunPtrTypeFloat div1 ;
void main()
{
HINSTANCE hDll;
hDll = LoadLibrary("C:/mydll/dllfun1.dll");
if(hDll == NULL)
{ cout<<"Error loading dllfun1.dll"<
}
add = (FunPtrTypeInt)GetProcAddress(hDll,"add");
if(add == NULL)
{
cout<<"error:"<<
}
sub = (FunPtrTypeInt)GetProcAddress(hDll,"sub");
if(sub == NULL)
{
cout<<"error:"<<
}
hDll = LoadLibrary("C:/mydll/dllfun2.dll");
if(hDll == NULL)
{
cout<<"Error loading dllfun2.dll"<
return ;
}
mul = (FunPtrTypeInt)GetProcAddress(hDll,"mul");
if(mul == NULL)
{
cout<<"error:"<<
}
div1 = (FunPtrTypeFloat)GetProcAddress(hDll,"div1");
if(div1 == NULL)
{
cout<<"error:"<<
}
int a,b;
cout<<"Enter a:";cin>>a;
cout<<"Enter b:";cin>>b;
cout<<"a + b = "<<
cout<<"a - b = "<<
cout<<"a * b = "<<
cout<<"a / b = "<<
}
====================================================
running to this program will show the result
Enter a:
45
Enter b:
12
a + b = 53
a - b = 33
a * b = 540
a / b = 3.750000

24 January 2007

3D effects of Fedora-core-6

path is => System | Preference | Desktop Setting
enable the effects,,, i will suggest you to download the Beryl that have very fantastic 3D effect
for that you have to go to => Application | Add Remove | search for Beryl and apply install to get mare effects...............

bookmarks : Best Way To Share Web Resource

Hi Friends
I Love Fedora core 6 (a Linux Operating System) and unbeatable Firefox 2.0 (best internet browser, i dont know why people use Internet Explorer),
In Firefox you can make a bookmark (just like add to favorite in IE), you can save a lot of time of browsing by adding links to bookmarks, you can even group bookmarks into "logical folders" ,
I use to add useful pages to bookmarks and organize them properly so that others get benefited,
in Firefox you can export and import the bookmarks, the feature is : it export all bookmarks as .html file ,,
come to the point now :
i think if we share our bookmarks , it will be best resource as you can easily find out good links and organized way, so My bookmark page is just resealed
http://narendra.sisodiya.googlepages.com/narendra_bookmarks.html
click it to see my bookmarks (hope somebody will definitely get benefit)
(i will update it regularly)
now what can you do is : you save this page and go to menu bar of firefox and click
Bookmarks | Organize Bookmarks ...
new window will pop up click
file | import | from file |
and give path of saved file narendra_bookmarks.html and click open
hope i will work properly to your system..........
publish your bookmarks also, Google provides ways to publish your files and pages..
but donot forget to send me a e-mail if publish your bookmark, i will make a mega bookmark page that will contain such bookmarks in very organized way... i need your help to help in case...
so hope we will see that bookmarks library soon so that every related information you will be able to achieve in few minutes.........

contact me : narendra.sisodiya@gmail.com

18 January 2007

UNIX shell programming

hi friends:
currently i am learning UNIX shell programming:
so i would like to give a good links related to it

1 hour Tutorial : This is very good for start up ....
Teach Yourself Shell Programming in 24 Hours : ultimate book for studying... no need to search any other book and online resource,,, first learn it fully ,,,it will take normally 1 month to master..
but you can go to two more resource after 5 to 6 days for programming......
Advanced Bash-Scripting Guide
you will also find many good examples at....Richard's UNIX Shell Scripting Universe

http://www.injunea.demon.co.uk/index.htm

as per my knowledge this is a good resource,,,, if you find a better one plz post comments here....

15 January 2007

Reverse the Linked List

Hi friend
This is a good example of algorithm and it related to data structure please try it and put you results here. we will discuss bad and good thing about your coding skill,

Q. Make a function that reverse the linked list. reversing the linked list means that the last element will becomes first one , again need not to go for fancy coding , you can work on algorithm also (best thing),

I have prepared nice ppt and coding algorithm that will tell how to do it efficiently, I will put but after getting some response to you. please ask queries here. tell friend about community may be he may need this community more than you.

Link
Solution:
Click here for Solution : http://www.techfandu.org/reverse_the_linked_list.html

01 January 2007

Scope Rule of for loop in C++










Q. what is the result of this program with and without static?

A.
variable i is defined at two place. So confusion arise as there are two i++, which i is incrementing at both place. Let name them as “frist i++” that is round bracket and “second i++” that is in curly bracket

Now if you see the diagram below then you will be at stage of giving answer.

The above code is equivalent to














Important thing is above diagram is curly brackets {} that tells the scope provided by a for loop. see outside i is initialized with zero, that has scope in main function. Statement i<5>

Now see curly brackets, in that i is defined as static means i will be created and assigned once that is if we some how managed to come again this place by goto statement or by using loop or calling the function again the statement will not execute moreover this will preserve its value also. statements like “second i++” an cout<<i will print value 5

so output will be

101

102

103

104

105

5

if static keyword is omitted then i inside curly bracket will be created again and again whenever loop runs

so the output will be

101

101

101

101

101

5

Q. now based on abode discussion i am modifying the code, don’t see answer now write your result first then and match it with my answer,






A.

see the difference , first field is empty and one more cout is present which has scope in main. so first i++ and cout<

the flowchart will be















so the result will be

101

1

102

2

103

3

104

4

105

5

5

readers can easily justify the output without static in this case

hey if you are on orkut why do not you join my "c++ help for all " community