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
Clone the Repository
First, clone the project repository to your local machine:Replace
<repository-url> with the actual URL of the repository.Verify Prerequisites
Check that you have the required compiler and make utility:Both commands should return version information without errors.
Build the Project
Compile the project using the provided Makefile:This will compile all source files with the following flags:
-Wall: Enable all warnings-Wextra: Enable extra warnings-Werror: Treat warnings as errors
.o) and generate the philo executable.Build Commands
The Makefile provides several useful commands:Compile the project
Remove object files
Remove object files and executable
Rebuild the entire project (fclean + make)
Source Files
The project consists of the following C source files:main.c- Entry point and program initializationinit_data.c- Data structure initializationparse_input.c- Command-line argument parsing and validationutils.c- Utility functionsmonitor.c- Death and completion monitoringphilo_actions.c- Philosopher actions (eating, sleeping, thinking)create_threads.c- Thread creation and managementtime_utils.c- Time-related utility functions
Troubleshooting
Compilation Errors
If you encounter compilation errors:- Ensure your C compiler supports C99 or later
- Verify that pthread library is available (
-lpthreadmay be needed on some systems) - Check that all source files are present in the directory
Permission Errors
If the executable cannot be run after compilation:The compiler used is
cc, which is typically a symlink to your system’s default C compiler (gcc or clang).