Skip to main content

Prerequisites

Before building the Philosophers project, ensure you have the following installed on your system:
  • C Compiler: GCC or Clang with C99 support
  • GNU Make: For building the project using the Makefile
  • POSIX Threads: pthread library (typically included with most Unix-like systems)
  • Unix-like Operating System: Linux, macOS, or WSL on Windows
This project uses POSIX threads (pthread.h) and may not compile natively on Windows without WSL or a POSIX compatibility layer.

Installation Steps

1

Clone the Repository

First, clone the project repository to your local machine:
git clone <repository-url>
cd philosophers
Replace <repository-url> with the actual URL of the repository.
2

Verify Prerequisites

Check that you have the required compiler and make utility:
cc --version
make --version
Both commands should return version information without errors.
3

Build the Project

Compile the project using the provided Makefile:
make
This will compile all source files with the following flags:
  • -Wall: Enable all warnings
  • -Wextra: Enable extra warnings
  • -Werror: Treat warnings as errors
The compilation process will create object files (.o) and generate the philo executable.
4

Verify Installation

After successful compilation, verify the executable was created:
ls -l philo
You should see the philo executable in your directory.

Build Commands

The Makefile provides several useful commands:
Compile the project
make
Remove object files
make clean
Remove object files and executable
make fclean
Rebuild the entire project (fclean + make)
make re

Source Files

The project consists of the following C source files:
  • main.c - Entry point and program initialization
  • init_data.c - Data structure initialization
  • parse_input.c - Command-line argument parsing and validation
  • utils.c - Utility functions
  • monitor.c - Death and completion monitoring
  • philo_actions.c - Philosopher actions (eating, sleeping, thinking)
  • create_threads.c - Thread creation and management
  • time_utils.c - Time-related utility functions

Troubleshooting

Compilation Errors

If you encounter compilation errors:
  1. Ensure your C compiler supports C99 or later
  2. Verify that pthread library is available (-lpthread may be needed on some systems)
  3. Check that all source files are present in the directory

Permission Errors

If the executable cannot be run after compilation:
chmod +x philo
The compiler used is cc, which is typically a symlink to your system’s default C compiler (gcc or clang).

Build docs developers (and LLMs) love