Put the libraries after your main.cpp
on the compilation command. The linker determines which symbols to pull out of those libraries based on the objects it's already seen, left to right.
As for your addendum question:
libname.a
is for static linking.libname.so
,libname.so.1.0
andlibname.so.1.0.0
are all the same file, just with names that give you an increasing level of version information granularity.
Which to use is beyond the scope of this answer, but you can find plenty of information about that already existing on the web.