What are C++ libraries?

#include <cmath>

I know that compiled object files .o, can only be used on the machine which compiled them. So what are libraries. Are they some kind of special object files that work for all machines, are they object files that are compiled on your machine when you install OS or compiler, or are they source files located in some folder in your computer and are compiled with your program.

Second question is how can I create my own? I have code that I want to use a lot without having to copy it into source directory.
google it
google it

That's not helpful on its own. Why not google it yourself and put what you find in the reply instead?
http://en.wikipedia.org/wiki/Library_%28computing%29
http://en.wikipedia.org/wiki/Static_library

are they object files that are compiled on your machine when you install OS or compiler

This is it, kind of. They are shipped with your compiler though.

Speaking of C and C++, their libraries sometimes are in a form similar to object files (pre-built for your compiler and OS), and they have an interface, which is the header. Did you notice that often the headers contain declarations and no code?

However for C++, an important part of its library is made of templates, which are left in text files that are compiled over and over again, as needed. So you will be able to find the actual code, not just an interface and a binary file.

Edit: relevant thread and links:
http://www.cplusplus.com/forum/beginner/35554/
http://www.adp-gmbh.ch/cpp/gcc/create_lib.html
http://msdn.microsoft.com/en-us/library/vstudio/ms235627.aspx
Last edited on
Thanks.
Topic archived. No new replies allowed.