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.
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.