Gattaca wrote:
Hello,
1. How can I create a personnal library (with my own functions) ?
2. How can I use it ?
I know that in my source code I will have something like
#include "mylib.h"
But how to make a link between mylib.h and the library compiled ?
a. Place all functions in a file with name "mylib.c".
b. Place all function declarations and other stuff (types,
macro's, #defined constants, ...) in the "mylib.h".
c. As you say, #include "mylib.n" in every source that
uses one or more of these library functions.
d. Compile "mylib.c", "source.c", ...
e. Link the object files into a program.
Step d. and e. can be done with one action/command for example:
cc source.c mylib.c -o myprog
This will invoke the linker as well. When you compile "source.c"
the compiler sees there are external functions (declared in "mylib.h")
and marks calls to them as unresolved. The linker makes a list
of all these unresolved externals and tries to find a match in
all object files it currently is processing. When there's a
match it fill in the right 'address' for each external.
HTH