Not; it includes only the title.
You compile the source separately and link it to your code that uses it.
For example (toy code):
stack.h
extern int pop(void); extern void push(int value);
stack.c
#include "stack.h" #include <stdio.h> #include <stdlib.h> enum { MAX_STACK = 20 }; static int stack[MAX_STACK]; static int stkptr = 0; static void err_exit(const char *str) { fprintf(stderr, "%s\n", str); exit(1); } int pop(void) { if (stkptr > 0) return stack[--stkptr]; else err_exit("Pop on empty stack"); } int push(int value) { if (stkptr < MAX_STACK) stack[stkptr++] = value; else err_exit("Stack overflow"); }
test.c
#include <stdio.h> #include "stack.h" int main(void) { for (int i = 0; i < 10; i++) push(i * 10); for (int i = 0; i < 10; i++) printf("Popped %d\n", pop()); return(0); }
Compilation
c99 -c stack.c c99 -c test.c c99 -o test_stack test.o stack.o
Or:
c99 -o test_stack test.c stack.c
So, you compile the source files (optionally create object files) and link them. Often, the stack.o
file stack.o
placed in a library (other than the standard C library), and you link to that library. This is what happens with the standard C library functions, of course. The C compiler automatically adds the C library (usually -lc
) to the bind command.
source share