Here's a step-by-step description of how I build static libs.
Let's say I wanted to create a static lib that contains a function: println(char*). I'll use only 1 function in my example for simplicity's sake. This function just prints a string and adds a carriage return at the end.
1. I create a new Static Library project. How you do this depends on what IDE you're using. Both MSVC and DevC++ support static library projects. MSVC generates .lib files and DevC++ generates .a files. Let's just say the output is printline.lib
2. I create this header file.
Code:
#ifndef _PRINTLINE_H_
#define _PRINTLINE_H_
#include <stdio.h>
void println( char* c ) ;
#endif
3. I create the implementation.
Code:
#include "println.h"
void println( char* c )
{
printf( "%s\n", c ) ;
}
4. I build the project. Your static library should be created (printline.lib or whatever).
5. Now I create a new project and create my main source file that uses my println() function. Notice it includes the println.h file.
Code:
#include "println.h"
int main(int argc, char *argv[])
{
println( "This is a line!" ) ;
getchar() ;
return 0;
}
6. Link the printline.lib file and build your project.