Chapter 1: Compiler

Introduction to Compiler and Interpreter

Compiler:

Process:

Interpreter:

Process:

Options to Run Code

Build

Description: Compiles all modified code files in the project or workspace/solution and then links the object files into an executable. If no code files have been modified since the last build, this option does nothing.

Usage:

make build  # Example command (depends on the build system)

Clean

Description: Removes all cached objects and executables so the next time the project is built, all files will be recompiled and a new executable produced.

Usage:

make clean  # Example command (depends on the build system)

Rebuild

Description: Combines the actions of "clean" and "build" to ensure a complete rebuild of the project.

Usage:

make rebuild  # Example command (depends on the build system)

Compile

Description: Recompiles a single code file regardless of whether it has been cached previously. This option does not invoke the linker or produce an executable.

Usage:

g++ -c file.cpp  # Example command for compiling a single file

Run/Start

Description: Executes the executable from a prior build. Some IDEs (e.g., Visual Studio) will invoke a "build" before doing a "run" to ensure you are running the latest version of your code.

Usage:

./executable  # Example command to run the executable

Additional Information

Compiler vs Interpreter

Compiler:

Interpreter:

Example Code Snippet

Here's a simple example of a C++ program and the steps to compile and run it using GCC:

// hello.cpp
#include <iostream>

int main() {
    std::cout << "Hello, World!" << std::endl;
    return 0;
}

Steps to Compile and Run:

1. Compile:

g++ -o hello hello.cpp

2. Run:

./hello