Empty C/C++ Project Template
A minimal, well-structured C/C++ project template with a production-ready makefile system. This template provides a quick starting point for new C/C++ projects with proper directory structure and build configuration.
Quick Start
Create Your Project
This is a template repository, which means you can create a new repository with the same directory structure and files very easily:
- Click the "Use this template" button at the top right of the repository page
- Choose "Create a new repository"
- Fill in your repository name and other details
- Click "Create repository" to finish
This will create a new repository in your account with all the template contents, giving you a fresh start for your project. Unlike forking, this method creates a clean project history.
Build Your Project
After creating your repository from the template:
# Clone your new repository git clone https://github.com/YOUR_USERNAME/YOUR_REPO_NAME.git cd YOUR_REPO_NAME # Build the project make # Run the executable ./empty-cpp
Clone and Build
Alternatively, you can fork this repository:
# Clone the repository git clone https://github.com/rantalaine/empty-c-cpp.git cd empty-c-cpp # Build the project make # Run the executable ./empty-cpp
Project Structure
empty-c-cpp/
├── src/ # Source files (.c, .cpp)
├── include/ # Header files (.h, .hpp)
├── build/ # Compiled object files (created during build)
├── makefile # Build configuration
├── LICENSE # MIT License
└── README.md # Project documentation
Makefile Explained
The makefile is designed to be flexible and maintainable while providing useful features for C/C++ development. Here are the key components:
1. Configuration Variables
PROG_BIN := empty-cpp # Name of the final executable BUILD_DIR := ./build # Where compiled files go SRC_DIRS := ./src # Where source files are located INC_DIRS := ./include # Where header files are located
2. Key Features
-
Automatic Directory Structure
- Automatically finds all
.c,.cpp, and.sfiles in the source directory - Creates necessary build directories on-the-fly
- Generates dependency files automatically
- Automatically finds all
-
Platform Detection
UNAME_S := $(shell uname -s) # Detects operating system
-
Flexible Include Paths
- Supports both local and system include directories
- Easy to add new include paths (just add to
INC_DIRS)
-
Dependency Tracking
- Automatically generates
.dfiles to track header dependencies - Only rebuilds what's necessary when files change
- Automatically generates
3. Build Targets
-
default: Builds the executable
-
clean: Removes build artifacts and executable
-
install: Installs the program to system (requires appropriate permissions)
-
uninstall: Removes the installed program
4. Compiler Flags
CPPFLAGS := $(INC_FLAGS) -MMD -MP -g $(CXXFLAGS) # Compiler flags
-MMD -MP: Generates dependency files-g: Includes debug information- Additional flags can be added via
CXXFLAGSenvironment variable
Customization
-
Change Project Name:
- Modify
PROG_BINin the makefile
- Modify
-
Add Libraries:
- Add library paths to
LIB_DIR - Add link flags to
LDFLAGS
- Add library paths to
-
Add Include Directories:
- Add new paths to
INC_DIRS
- Add new paths to
-
Platform-Specific Settings:
ifeq ($(UNAME_S),Darwin) # MacOS-specific settings endif
Notes
- The makefile automatically detects source files, so you can just add new
.cppor.cfiles to thesrcdirectory - Header files should go in the
includedirectory - The build system creates object files in the
builddirectory, maintaining the same directory structure as your source files