CS253: Software Development with C++

Spring 2023

How I Compile

Show Lecture.HowICompile as a slide show.

CS253 How I Compile

How I Compile C++ Programs

made at imgflip.com

Jack didn't use an IDE like Eclipse. He worked from the command line. He used vim to edit, and cmake/make/g++ to compile.

Jack would say "if you always use an IDE, then you can only use an IDE." This makes you much less flexible/valuable as an employee. Imagine trying to get a job as a driver, when all that you can drive are Ford trucks with automatic transmissions. You’re not worth the bother. They’ll hire someone who can drive a wider range of vehicles.

Logan's Arguments

Knowing how to use an IDE is not bad.

However, if you can't comprehend or analyze code outside of the IDE that is bad.

A programmer doesn't Just write code, they need to comprehend and critically understand code.

Sometimes you need to do things manually to reach that point

Flags

g++ -std=c++17 -Wall -Wextra -Wpedantic -Werror -Wfatal-errors foo.cc

Option Action Why
-std=c++17 C++ 2017, no extensions default is C++14 with non-standard extensions
-Wall “all” warnings required in this class
-Wextra more warnings the compiler is your friend
-Wpedantic even more warnings the compiler is your only friend
-Werror treat warnings as errors don’t tolerate warnings; avoid losing points
-Wfatal-errors give up after the first error the only one you should look at

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. In this class, we use cmake and make, so you don’t have to type it.

“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 or CMakeLists.txt:

    g++ -fmessage-length=80 -fno-diagnostics-show-option
        -fstack-protector-all -g -O3 -std=c++17 -Walloc-zero -Walloca
        -Wctor-dtor-privacy -Wduplicated-cond -Wduplicated-branches
        -Werror -Wextra-semi -Wfatal-errors -Winit-self -Wlogical-op
        -Wold-style-cast -Wshadow -Wunused-const-variable=1
        -Wzero-as-null-pointer-constant

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. Anyway, I don’t type it all every time—I copy it.

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 search for another profession.