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 KennRiliSaby, 06/13/2017 at 9:32pm (UTC):
Ciprocinal Tablete <a href=http://viacheap.com>viagra</a> Amoxicillin 500 Side Effects Cat Bite And Keflex <a href=http://cial40mg.com/generic-cialis-pricing.php>Generic Cialis Pricing</a> Purchase Fluoxetine Discount Australia With Free Shipping Canadian Pharmacie For Cialis <a href=http://viagra-100mg.via100mg.com>Viagra 100mg</a> Occasion Levitra Top Canadian Pharma Companies <a href=http://buy-levitra-20mg-usa.buylevi.com>Buy Levitra 20mg Usa</a> Viagra Generic Vs Brand Viagra Efectos Indeseables <a href=http://priligy-usa-sale.priliorder.com>Priligy Usa Sale</a> Propecia Tienda Buy Viagra In The Usa <a href=http://propecia.ccrpdc.com/shop-propecia.php>Shop Propecia</a> Medicine Without A Prescription Levitra Generique Montreal <a href=http://cheap-kamagra-pills.kamagpills.com>Cheap Kamagra Pills</a> Cialis Cost Per Pill

Comment posted by XRumerTest, 05/14/2017 at 8:53pm (UTC):
Hello. And Bye.

Comment posted by JeroScienda, 05/10/2017 at 8:04am (UTC):
Propecia 15 Rebate Cheap Drugs From Canada Amoxicillin And Clavulanate Potassium Tablets Usp Finasteride Can I Purchase Problemas Con Propecia <a href=http://byuvaigranonile.com>viagra</a> Levothyroxine Without A Script Cheap Generic Viagra Uk

Comment posted by XRumerTest, 04/21/2017 at 12:20pm (UTC):
Hello. And Bye.

Comment posted by DonaldBLOCA, 04/21/2017 at 11:46am (UTC):
<a href=http://vardenafilprixenpharmacieacaen.com/>vardenafil prix en </a>
<a href=" http://vardenafilprixenpharmacieacaen.com/ ">levitra prix en pharmacie </a>

Comment posted by AnthonyPoilM, 04/16/2017 at 7:40pm (UTC):
<a href=http://acheterazithromycinesansordonnance.club/>acheter azithromycine sans ordonnance </a>
<a href=" http://acheterazithromycinesansordonnance.club/ ">acheter azithromycin canada </a>

Comment posted by Perrygow, 04/16/2017 at 5:11pm (UTC):
<a href=http://wherecanibuyviagraonline.us/>where can i buy viagra over the counter in usa </a>
<a href=" http://wherecanibuyviagraonline.us/ ">where can i buy viagra over the counter in europe </a>

Comment posted by JamesErarf, 04/16/2017 at 1:12am (UTC):
<a href=http://acheterventolinespraysansordonnance.com/>acheter ventolin spray paint </a>
<a href=" http://acheterventolinespraysansordonnance.com/ ">acheter ventolin spray sans ordonnance </a>

Comment posted by Anthonysaf, 04/15/2017 at 3:44pm (UTC):
<a href=http://acheterfinasteridesansordonnance.com/>acheter finasteride en france </a>
<a href=" http://acheterfinasteridesansordonnance.com/ ">finasteride 5 mg acheter </a>

Comment posted by LeonardTob, 04/15/2017 at 2:10am (UTC):
<a href=http://acheterprednisone20mgenligne.com/>acheter prednisone 20 mg en ligne </a>
<a href=" http://acheterprednisone20mgenligne.com/ ">achat prednisone en ligne </a>



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

Today, there have been 1 visitors (8 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