C++:
Starting a new project

How to:

When starting, choose your build system or IDE. For simplicity, we’ll use a basic text editor and g++. Create two files: main.cpp and a Makefile.

main.cpp:

#include <iostream>

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

Makefile:

all:
    g++ main.cpp -o my_project

clean:
    rm my_project

To compile, run make in the terminal. To clean up, run make clean.

Sample output after running ./my_project:

Hello, new project!

Deep Dive

Historically, setting up a new C++ project was a more manual process. Today, IDEs can generate templates. Choices like CMake or Meson help manage builds. Before these tools, developers wrote Makefiles by hand, compiling every .cpp file into an object file before linking them.

Considering alternatives: newer build systems simplify the process. For example, CMake autogenerates your Makefiles, making it platform-independent.

Implementation-wise, the setup depends on factors like project size and dependencies. Larger projects demand a more complex structure with separate folders for source files, headers, and tests.

See Also