Hi,
Well, i'd like to know how does the libs work. I mean, when in linux for ex, i make a program and include the stdio.h ( in stdio.h i only hace the heads ), how do the OS to include the function and not only the header? I want to do this libc, but don't know where to start.
bye.
Libs
Re:Libs
Compile your C library sources to .o files as normal. Combine these into one .a using the ar program:
Code: Select all
ar rcs libc.lib strcpy.o strlen.o fopen.o
Re:Libs
Tim,
I was not able to understand (right (?)) what's asked and what was answered! Sorry about that!
You gave example: ar rcs libc.lib strcpy.o strlen.o fopen.o
Now, Is this ar utility by any means replacing existing functionality of strcpy, strlen, fopen in libc.lib gets replaced with custom strcpy, strlen, fopen.
Is this correct?
Thanks in advance!
Regards,
Aditya.
I was not able to understand (right (?)) what's asked and what was answered! Sorry about that!
You gave example: ar rcs libc.lib strcpy.o strlen.o fopen.o
Now, Is this ar utility by any means replacing existing functionality of strcpy, strlen, fopen in libc.lib gets replaced with custom strcpy, strlen, fopen.
Is this correct?
Thanks in advance!
Regards,
Aditya.
Re:Libs
Libraries are just collections of object files (*.o). The format of what is in the library is pretty un-important, but you can look at it under windows with things like DUMPBIN and LIB /L. Under Linux most of these tools will be combined into 'ar', but basically at the heart of it all, just think of it as like a ZIP file (or a closer relative would be a TAR file).
So in anycase you create the library (be it a .a or .lib) with an external utility. Now when you want to compile against that library you just need to tell the compiler it is a library and not a normal object file. This is done with compiler switches and under unix is usually "-l".
So for example I want to create a library with:
strcmp.c and strlen.c
I first compile them to obj files:
cc -c strcmp.c
cc -c strlen.c
Now I create the library (as Tim showed)
ar rcs stdlib.a strcmp.o strlen.o
And to compile the program and link against the library:
cc main.c -l stdlib.a
There are other things to think about when using libraries such as static data, circular dependancies and stuff, but all in all this is really pretty simple and is also pretty basic programming stuff. You might do well by getting some programming books.
_mark()
So in anycase you create the library (be it a .a or .lib) with an external utility. Now when you want to compile against that library you just need to tell the compiler it is a library and not a normal object file. This is done with compiler switches and under unix is usually "-l".
So for example I want to create a library with:
strcmp.c and strlen.c
I first compile them to obj files:
cc -c strcmp.c
cc -c strlen.c
Now I create the library (as Tim showed)
ar rcs stdlib.a strcmp.o strlen.o
And to compile the program and link against the library:
cc main.c -l stdlib.a
There are other things to think about when using libraries such as static data, circular dependancies and stuff, but all in all this is really pretty simple and is also pretty basic programming stuff. You might do well by getting some programming books.
_mark()