Compiling C++ code


C++ Compilation on Linux Mint
C++ Compilation Process:
We write C++ code in files with .cpp or .c++ extensions.
We give these files to C++ compiler(which is g++) to compile.
The compiler compiles our source files into an executable file(a binary file).
We run or execute that binary file when we want to use our program and get the output.
So, its a two-step process:
Compile
Run or Execute
Note: Binary files on linux generally have no extensions.
Steps:
To compile:
g++ -std=c++17 -Wall -Wextra hello.cpp -o hello
Here:
g++ is the compiler name.
-std=c++17 → This says to the compiler that our code is using c++17 standard (latest version).
-Wall and -Wextra → give warning messages for errors in our code.
hello.cpp is our c++ source file name.
-o specifies the output(binary) file name, which is hello.
To run or execute:
./hello
Runs the hello binary which is present in current directory.
Done!
Subscribe to my newsletter
Read articles from csm directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
