Great students like us work on the principle of Rockets.. It does not mean tht we aim to the sky..But we dn't work hard untill our tail is on fire..

Ankit - Born 2 Code - Create your own library file in C
This tutorial shows you how to create your own Library file & Header file
--------------------------------------------------------------------------------------------------------------
Creating library is very simple than writing a program.
( Here i m showing the example to add a new function swap() to C library
    --which will swap values of two integer variables )

Step 1 :
    Write your functions(i.e,Function definition without 'main' function) in a 'C' program file.
    for example:
/* swap.c */
#include<stdio.h>
void swap(int x,int y)
{
    int z;
    z=x;
    x=y;
    y=z;
    printf("nAFTER SWAPPING");
    printf("nFIRST  NUMBER >> %d",x);
    printf("nSECOND NUMBER >> %d",y);
}

Step 2 :
    Create a header file. The header file must have the function declarations of your functions(i.e,     Function prototypes).
    for example:
/* swap.h */
#ifndef __SWAP_H
    #define __SWAP_H

    #ifdef __cplusplus
    extern "C"{
    #endif

    void     _Cdecl swap(int x,int y);

    ifdef __cplusplus
    }
    endif
#endif


Step 3 :
    Compile your 'C' source code file.Compiler will produce the object code (i.e, '.obj' file).
------------Process 1--------------------
    Using TCC utility (Turbo C complier) make the obj file.
    (you will find TCC.exe in ur c:/tc/bin directory....)
    ...make sure tlib.exe and swap.c both are in same folder....
    (if u r facing any error try to run this command in command prompt)
    for example:
TCC -c swap.c swap.obj
    you will get -- swap.obj

------------Process 2--------------------
    open your source file swap.c in turbo c++ editor
    compile it using Alt+F9
    you will get -- swap.obj

Step 4 :
    Using TLIB utility make the lib file.
    (you will find TLIB.exe in ur c:/tc/bin directory....)
    ...make sure tlib.exe and swap.obj both are in same folder....
    (if u r facing any error try to run this command in command prompt)
    for example:
TLIB swap+swap.obj
you get: swap.lib

The above process will help you to create library file n header file for ur own functions...


Using Library file & Header file in your programme
-----------------------------------------------------------------------------

Now you have to do some extra job-----
    1) Put the swap.h file in c:/tc/include directory
    2) Put the swap.lib file in c:/tc/lib directory

    Now you can create a programme to use your own library function
    for example:
/* main.c */

/*swapping using library function of swap.h*/
#include<stdio.h>
#include<conio.h>
#include<swap.h>

void main()
{
    int a,b;
    clrscr();
    printf("PLEASE ENTER FIRST  NUMBER : ");
    scanf("%d",&a);
    printf("PLEASE ENTER SECOND NUMBER : ");
    scanf("%d",&b);
    swap(a,b);
    getch();
}

    Now run your programme - Ctrl+F9
    You will see an error-- "undefined symbol _media in module uselib.c"
    This shows you hv not done your job completely, as i didn't tell u to do so.....
   
    So, let's move ahead--
    The reason behind this error is---
    you have put swap.lib n swap.h in lib and include directories respectively.
    But the complilor is unable to include the library file swap.lib automatically...
    Hence the error....
   
    Now you have the following 3 ways for running your programme........
    1) Run your programme using TCC.exe
    2) Run your programme by creating a project in C
    3) Run your programme by linking your swap.lib to Standard C library -CS.lib

   
Run your programme using TCC.exe
--------------------------------------------------------
    Again you have three options
    (all files shhould be in same folder)
    Option 1:
TCC main.c swap.c
    Option 2:
TCC main.c swap.obj
    Option 3:
TCC main.c swap.lib

    You can use any one of the three options, the result is same-
    You get the main.exe file..
    Now you can run main.exe..
    You will get the output.


Run your programme by creating a project in C
------------------------------------------------------------------------
    Open a project named 'swap.prj' in the 'project' menu using 'open project' option.
    Then insert the 'main.c' and 'swap.lib' in the project by pressing 'ins' key
    or by selecting 'project -> insert' in the menu bar.
    Then you run the 'main.c' by pressing 'Ctrl+F9' key.
    You will get the output.
    As the above method - You can use either one of the files-- 
        swap.c or  swap.obj or swap.lib


Run your programme by linking your swap.lib to Standard C library -CS.lib
-----------------------------------------------------------------------------------------------------------------
    This is the most exciting method for running your programme...
    (and of course last for me to type..)
    By using this method you will be able to use your library function
    And in the same way as you use other library functions..
    See how i made it possible.....
Step 1:
    First you have to link you file swap.lib with standard C Library cs.lib
    Using TLIB utility make the lib file.
    (you will find TLIB.exe in ur c:/tc/bin directory....)
Step 2:  
    Paste cs.lib from c:/tc/LIB/ directory to the folder where tlib.exe and swap.lib are saved.. (generally c:/tc/bin/ )
   
    ...make sure all files are in same folder....
    (if u r facing any error try to run this command in command prompt)

    for example:
    Option 1:
TLIB cs+swap.obj
    Option 2:
TLIB cs+swap.lib

    You can use any one of the two options, the result is same-
    You get : cs.lib (update version)

Step 2:
    Now put the file cs.lib in c:/tc/lib directory
    From now on you will be able yo use your new library function swap()
    and in the same way as you use other library functions...
    open main.c in c editor
    run using - Ctrl+F9
    You will get the output.
----------------------------------------------------------
Downloads---
Dwnld 1) Download example files here
Dwnld 2) If you have lost original CS.LIB you can dwnld it
-----------------------------------------------------------------------------------------------------------
            TESTED FOR C++ ALSO........
-----------------------------------------------------------------------------------------------------------
HAPPY CODING...........
ENJOY................
koolankit.mzn@gmail.com

page created by - Ankit Goel (on 25-dec-2008 at 1:00 p.m. IST)
(Last Updated on 26-dec-2008 at 12:00 a.m. IST)






The last comments on this page:
Comment posted by nlmmdahab, 09/14/2017 at 10:27pm (UTC):
payday loans bad credit <a href="http://paydayloans2017.com"> payday loans mn</a> <a href="http://paydayloans2017.com"> best payday loans</a> <a href=http://paydayloans2017.com>payday loans online</a> payday loans online same day

Comment posted by nuwwizhab, 09/10/2017 at 6:38am (UTC):
payday loan lenders <a href="http://paydayloans2017.com"> payday loan</a> <a href="http://paydayloans2017.com"> payday loans near me</a> <a href=http://paydayloans2017.com>payday loans online no credit check</a> direct lender payday loans

Comment posted by nilytxhab, 08/26/2017 at 10:23pm (UTC):
ace payday loan <a href="http://cashadvances2017.com"> payday loans mn</a> <a href="http://cashadvances2017.com"> payday loans mn</a> <a href=http://cashadvances2017.com>online payday loan</a> no credit check payday loans

Comment posted by Everettguipt, 07/25/2017 at 10:36pm (UTC):
viagra swallow whole or let disolve
<a href=http://buyviagraestonline.com/>when viagra patent expire
</a>
<a href="http://buyviagraestonline.com/">viagra falls pete hart
</a>
don't mix viagra wih steroids photo

Comment posted by StephenScuck, 07/25/2017 at 8:54pm (UTC):
viagra fraudster
<a href=http://buyviagraestonline.com/>viagra</a>
<a href="http://buyviagraestonline.com/">buy viagra</a>
poland viagra without prescription

Comment posted by JasonAxorp, 07/23/2017 at 11:50am (UTC):
viagra falls movie pics
<a href=http://buyviagraerxonline.com/>view web page
</a>
<a href="http://buyviagraerxonline.com/">buy viagra online</a>
viagra female testimonials

Comment posted by JasonAxorp, 07/23/2017 at 9:14am (UTC):
viva viagra ringtone
<a href=http://buyviagraerxonline.com/>buy viagra online</a>
<a href="http://buyviagraerxonline.com/">buy viagra</a>
mecican viagra

Comment posted by JasonAxorp, 07/22/2017 at 2:42pm (UTC):
female viagra chocolets
<a href=http://buyviagraerxonline.com/>online viagra</a>
<a href="http://buyviagraerxonline.com/">online viagra</a>
viagra mycoxafloppin

Comment posted by XRumerTest, 07/20/2017 at 6:50pm (UTC):
Hello. And Bye.

Comment posted by AnthonyVok, 07/19/2017 at 8:52pm (UTC):
definition essay for real friendship
<a href=http://writingservicestop.com/>online help writing classificationdivision essay
</a> product design assignment help
<a href="http://writingservicestop.com/">top quality essay writing services
</a> custom essay writing reviews



Add comment to this page:
Your Name:
Your message:

Today, there have been 80 visitors (589 hits) on this page!
=> Do you also want a homepage for free? Then click here! <=
Page copy protected against web site content infringement by Copyscape