Show Lecture.HowICompile as a slide show.
CS253 How I Compile
How I Compile C++ Programs
I don’t use an IDE, like Eclipse. I work from the command line. I use
vim to edit, and g++
to compile. You may edit and compile your
programs however you like—I just expect you to turn in a .cc
file.
How you produce it is your affair.
Flags
g++ -std=c++14 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors foo.cc
-std=c++14
: Compile strict C++ 2014, without GNU extensions.
-Wall
: Produce all warnings.
-Wextra
: Produce more warnings.
-Wpedantic
: Produce ultra-fussy warnings.
-Werror
: Treat warnings as errors.
-Wfatal-errors
: Give up after the first error.
Too Hard
“But that’s too hard to type every time!” 🎻
You don’t have to type it every time. Type it once, and use shell
history (!g
) to do it again. Or, you could write a two-line bash
script. I use Makefiles.
“But I’ll never remember all that!”
You want to be a professional computer programmer, and you’re still
relying on meat-based memory? Write it down. Get Dropbox,
Evernote, Google Drive, or some kind of permanent storage. Use a
notebook and a pen if you’re old-school. You’re going accumulate data
for the rest of your life. Start doing it right.
More Flags
However, when I get really serious, as in a Makefile
:
g++ -g -std=c++14 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors
-Winit-self -Wshadow -Wlogical-op -Wcomment -Wctor-dtor-privacy
-Wold-style-cast -fno-diagnostics-show-option
-fmessage-length=$COLUMNS foo.cc
Too Too Hard
“But that’s ridiculous! I shouldn’t have to type all that.”
Yeah, you shouldn’t—it’s terribly unfair. If life were fair, then the
compiler would do all that by default, and ice cream would be good for
you. Get over it. I don’t type it all every time—I copy it.
Also, I compile an important program with more than one compiler.
Different compilers generate different warnings.
clang++
works well on Linux.
Do you want fries with that?
“More warnings? Why on earth would I want more warnings!?”
I wish you the best of luck with your career in the fast-food industry.