how to make linux static library



In Linux OS, known (shared) libraries have .so extension, static library has .a extension and its creation is pretty easy. You can create static libraries with header or without header. I create it with its header in this subject.

First of all, the header file (Welcome.h) is prepared.


#include <stdio.h>
void printWelcome();

Then, its implementation (Welcome.cpp) file is written.

#include "Welcome.h"
 
void printWelcome()  {
    printf("Hello World !");
    return;
}

After these steps, the .c is complied and the static library is created.

ar -cvq libWelcome.a Welcome.o
Note: ar command has a lot of parameters, you can check them.

Finally, main file is created to test library.


#include "Welcome.h"

int main()  {
  printWelcome();
  return 0;
}


After main file is complied, when it is linked, libWelcome.a or -L /<dir> -lWelcome parameter is specified.

Popular posts from this blog

Polya’nın Problem Çözme Teknikleri

Mikroislemci Temelleri