I am curious to know how I can make my own library and use it for my C/C++ programs? I mean I want to make a library say "maths_example" which will have 2-3 files having some basic functions of maths. Then, I want to use that library for my programs which I will write after writing

#include "addition.h" 
#include "substraction.h"

So that now, I can use my functions written in my own library. I just want to learn the things how we make library, how we compile all files in library simultaneously, how we use our own written functions in our written codes as we do for "printf()", "sqrt()" etc. Can anyone help me how to start with this? Can you give me links from where I should read about this and start learning this?
If you can give me some example, then it would be beneficial. Any help would be appreciated.

2 Years
Discussion Span
Last Post by nitin1

How you do this depends upon you compiler and operating system. Read the relevant documentation for you system on how to create a static or shared library.


I am using Dev Cpp/ eclipse as the IDE. I am using windows/linux. I just want to learn how these things work. May be any platform, any compiler, I just want to do the complete procedure myself. From creating library with few files and adding it to my project and finally use the library functions in my programs. What documentation are you talking about? Thanks for your reply.

Edited by nitin1


May be any platform, any compiler, I just want to do the complete procedure myself.

The complete procedure really does vary between compilers and operating systems and the documentation for your compiler will give you specific instructions.

For a static library it's super easy. Just create a standalone project with the functions and types you want, compile, and add the resulting object files to a static library file (typically .a or .lib). From there you link to the library file as normal.

Shared libraries may be a smidge harder depending on your OS. DLLs in Windows require some coding effort in the library itself, for example.


@deceptikon Mike has explained it really well and I am reading it completely now not only the section. Can you give me more inforamtion about dlls? I mean some good links after giving me some brief introduction from your side. It would be helpful. {P.S Interacting with you after so long time :) }

@mike thanks for the link. It helped me a lot as that post has many things which were not in my knowledge earlier.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.