From http://www.learncpp.com/cpp-tutorial/19-header-files/

How does the linker know that it needs to include the standard runtime library and for example the definitions of the functions declared in iostream are not present elsewhere?
Is there some mapping that facilitates the linking process?
To rephrase – If I include some file with only function declarations, how does any linker figure out where the function definitions are?
If you use
g++, it will always link the standard c++ library (-lstdc++).To bypass it, you can use
gccand link a different library.Edit: the linker doesn’t figure out anything. The standard library is automatically linked, so there’s nothing to figure out for the standard functions. If you just declare something that is not in STL and try to use it without the actual definition, the linker will fail. You have to manually link the library/.o.