Suppose I want to know which library will be added by invoking -lm flag, how do I do that?
The part after the -l is the name of the library. Its binary is prefixed with lib, so you can find them by that name;
> whereis libm
libm: /usr/lib64/libm.a /usr/lib64/libm.so
> whereis libcairo
libcairo: /usr/lib64/libcairo.so
Etc.
If whereis does not say anything, you can also try grepping the output of ldconfig -p (see man ldconfig):
> ldconfig -p | grep "libm.so"
libm.so.6 (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib64/libm.so.6
libm.so.6 (libc6, OS ABI: Linux 2.6.32) => /lib/libm.so.6
libm.so (libc6,x86-64, OS ABI: Linux 2.6.32) => /lib64/libm.so
Notice in this case I've appended "libm" with ".so", which is not necessary, but it saves matching against "libmfoo...", "libmbar...", etc. Since -l refers to linking shared object (.so) libraries, this should be pretty foolproof.