#1
  1. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12

    How to make .lib .dll .obj of my functions


    I wrote a lot of string functions, I want to use them without recompiling everytime. I tried getting the .obj file but.. they won't compile without a main(). I have the prototypes in X.h, how would I get my functions in a .dll? do I need to make any changes? what about .lib?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    31
    Rep Power
    11
    halo

    the reason why compiler complains abt main() is because by default it compiles the source to an executable...

    to prevent this, u need to include the "-c" option. This will create a non-executable binary object file.
    Using conventional naming, the object file compiled is of file extension ".o"

    for example:

    $ gcc -c mylib.c
    this will create by default mylib.o object file.
    mylib.c is just a set of library codes and does not contain any main().

    To use this object file:
    $gcc -o myHelloWorld.exe mylib.o myHelloWorld.c

    thils will compile my calling program with the object file...

    You can tar multiple object files into a single archived file (usu file extension of ".a") and use that archived file as if its a single object file when compiling with other calling programs...:

    $gcc -o myCallingProg.exe myBigLibCollection.a myCallingProg.c


    After all this, i must add that my personal preferences after encountering many linkage problems in the past while attempting to compile STLs and porting, I prefer to avoid unnecessary libraries. I would put all my codes in the header files and have all my calling programs to #include them when needed. (its the way sgi stl do it and i like it, just my own preference... )

    Hope it helps a little...
    Sorrie if it doesnt...
    Last edited by siddy; August 19th, 2003 at 11:45 AM.
  4. #3
  5. Cast down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Sweden
    Posts
    321
    Rep Power
    12
    NM, fixed it, was missing a ; ^_^
    Last edited by movEAX_444; August 19th, 2003 at 02:01 PM.

IMN logo majestic logo threadwatch logo seochat tools logo