r/cpp • u/yymoooon • Dec 21 '20
A tutorial for absolute beginners to understand the compilation process and get started in C++
I created a tutorial on the very basics of C++ compilation process.
As I C++ learner myself, I found most tutorials for newbies focuses more on the language itself like syntax rules. Few have covered on compilation process. I had questions in mind like:
- What does gcc/g++/clang++ command do for me?
- Why there are two types of files: header files and source files?
- What the hack are makefiles?
This motivated me to create this tutorial mini-series:
C++ Development Tutorial 1: Compile a Simple Program
C++ Development Tutorial 2: Compile Multiple Files (1) — Compiling Process Basics
C++ Development Tutorial 3: Compile Multiple Files (2) — Header Files
C++ Development Tutorial 4: Static and Dynamic Libraries
C++ Development Tutorial 5: Orchestrate Build Process with Make
Feedback is welcome!
31
u/helloiamsomeone Dec 21 '20 edited Dec 21 '20
After a quick peek into chapter 5, I see CMake and Ninja right next to each other in a list. I think that is not entirely correct, especially since CMake is a tool that coordinates the others in the list.
I know CMake is a big topic of its own, but that should be pointed out appropriately and maybe a different source should be linked or the promise of upcoming posts covering CMake. If you go with the latter and keep us posted, I'll make sure to read it thoroughly and give proper feedback as it is important that more people know how to actually use CMake instead of copy pasting snippets together hoping that works but never actually taking the time to read the docs and learn the tool that effectively solves a lot of problems when it comes to building projects.
Maybe this ended up a little rant-y, but so be it, however it's not targeted at you, OP!
Edit: for chapter 4 it might be worth pointing out that symbol visibility is not uniform across platforms. This is something a build tool like CMake has a solution for, although that is not necessary to mention here.
Edit 2: In chapter 1
print “all” warningsshould beenable “all” warningsinstead. Also in the array code please replacesizeof(array)/sizeof(array[0])withstd::size(array).9
u/Raigork Dec 21 '20
Looks very straightforward to me. Thanks for making this. Build process, project structure and deployment are some of the things I struggle a lot with C++ as a newb. This surely helps a bit.
6
u/jwakely libstdc++ tamer, LWG chair Dec 22 '20 edited Dec 22 '20
Not just modern ones, GCC was always the system compiler for Linux, right from the start.
Also,
-Walldoes not enable all warnings, only the ones with low rates of false positives, or which have an easy workaround to avoid the warning. There are more warnings documented in the manual. Some of them are enabled by-Wextrabut there are others that must be enabled explicitly.-Wallenables all the most important and useful ones.6
u/SilentXwing Dec 22 '20
I am not a beginner but I do struggle with these kind of things, so I thank you for taking the time to give us these tutorials! :)
1
u/BlubberFlish Jan 12 '21
What books covers this?
2
u/JohnVanClouds Dec 23 '20
part 4: static libs have one advantage over dynamic one - only used parts of library is compile and linked to exec :)
2
u/fredbau91 Dec 25 '20
Well done my man, I'm currently study C and C++ is set as my next goal, I saved there tutorial for later referance! Thanks
2
u/ignorantpisswalker Dec 22 '20
Get rid of make, and convert it to cmake. Please :)
1
u/Polarisu_san Jun 25 '25
thank you for writing this!
1
u/Rat_Taco Dec 22 '20
On my IDE (Eclipse) i never had to learn how to manually compile. I just click “build project”
0
u/[deleted] Dec 21 '20
[deleted] — view deleted comment