In this post you will learn how to create you own C C++ library files. I assume you have a basic knowledge of programming in Linux, good knowledge of the C C++ basics and C C++ libraries. The libraries can be of two types object files and archive file (.a files). The object files in turn can be of two type static object (.o files) and shared object (.so files). Lets begin to create the library. Create a folder named Library in that folder create three file with the contents as shown below

1. main.cpp
2. add.cpp
3. mul.cpp

Enter the command $> gcc -c add.cpp mul.cpp to create the object (.o) file. Two new object files add.o and mul.o will be created in the folder. Enter the command $> ar -q  libmath.a add.o mul.o to conbine the object files into a single archive (.a) file. This will create the file libmath.a That is all, you have created you own object files and archive file. Now that the object files and archive file are ready lets see how to use these.

There are two ways to use these file one is to link single archive file or link every required object file. Here I have shown both the ways. Enter this command $> gcc main.cpp -lmath to link wiht the archive file or $> gcc add.o mul.o main.cpp to link with the object files.