For just one file, g++ -W -Wall -Wextra -pedantic -std=c++11 -O3 -march=native -g -o filename sourcefile.cc
(that -std=c++11 may be replaced by -std=c++0x for pre-4.7 versions, or by -ansi if you need to limit the compiler to the 2003 C++)
That's another question I have. How do makefiles work exactly? And how would I create one? Sorry for the beginner question...I'm relatively new to the language.
Makefiles aren't part of the (C++) language, they are part of Unix development environment. A makefile is a text file that contains instructions to the program called "make", essentially lists of commands to run in order to build (or install, or do something else to) the project.
The language of makefiles is fairly complicated in general case, which is why reading makefiles from other programs is not going to be helpful, but hunt around for tutorials and documentation: simple makefiles are, well, simple. Also check out alternatives, I liked the python-based program called scons.
Sure. Add a few more files and you may want to at least write a a shell script that runs the command(s) you just typed... Or at least a text file to paste from. I suppose until you need something that tracks dependencies, you may be fine with that.
The reason to use makefiles is to avoid recompilation.
As long as the source or some dependency (include) does not get modified, you don't need to compile that file, but just link it.