There are two types of libraries:
This is good tutorial on their differences and how to build and linking them. Alternatively, how to create libraries is described here.
Note: When the GNU linker sees a library, it discards all symbols that it doesn’t need. Thus if the library appears before the .cpp or .o files in the linking command, then the library is being discarded before the .cpp file is compiled and you might get an undefined reference error. Hence, the libraries must come last in the linking command:
g++ -o main.exe main.cpp -L. -lmylib