Project Building
1. Basics of Compiling
Compiler sequentially goes through each .cpp file and:
- check if the code follows the rules of the language, if not then release an error and abort compilation.
- translates the code into machine language which is stored in an object file (
.oor.obj)
Linker then:
- checks all cross-file dependencies, can release errors
- links up library requested files
- creates the desired output file, usually an executable
[!note]
Because there are multiple steps, the process of converting source code into an executable is often reffered to as building.
1.2. Compiling flags
General flags:
-ospecifies the name/path of the output file-pedantic-errorsdisables compiler extensions
Flags that raise the error level:-Wall -Weffc++ -Wextra -Wconversion -Wsign-conversion-Werrortreats warnings as errors
Setting the language standard:-std=c++14for setting the standard as C++14 or whatever else
[!tip]
Quick flag setup using all of the above:g++ -o -pedantic-errors -Wall -Weffc++ -Wextra -Wconversion -Wsign-conversion -std=c++14 -Werror
-
Debug build flags #stub
-
-ggdbidk yet? -
-O0no optimizations, it's the default but still -
Release build flags
-
-O2recommended optimizations that work on most programs