A GUI-based calculator developed in C using GTK.
Welcome! This comprehensive guide will help you get up and running with the C GUI Calculator built using GTK+ 3. Whether youโre a beginner or experienced developer, this guide provides detailed platform-specific instructions to clone, install dependencies, compile, and run the calculator successfully.
By following this guide, you will:
Before compiling, ensure the following packages are installed on your system:
| Component | Purpose | Linux Package | Windows (MSYS2) | macOS (Homebrew) |
|---|---|---|---|---|
gcc |
C compiler for building the application | gcc |
mingw-w64-x86_64-gcc |
gcc |
pkg-config |
Manages compiler/linker flags for libraries | pkg-config |
mingw-w64-x86_64-pkg-config |
pkg-config |
libgtk-3-dev |
GTK+ 3 development files for GUI | libgtk-3-dev |
mingw-w64-x86_64-gtk3 |
gtk+3 |
๐ Note: See our detailed Requirements Guide for comprehensive package information and alternative installation methods.
First, clone the project repository to your local machine:
# Clone the repository
git clone https://github.com/rafisarkar0128/c-gui-calculator.git
# Navigate to the project directory
cd c-gui-calculator
# Verify the files are present
ls -la
Expected output:
main.c # Main source code
README.md # Project documentation
Getting-Started.md # This guide
Requirements.md # Detailed requirements
LICENSE # MIT license
.gitignore # Git ignore rules
Choose the appropriate instructions for your operating system:
# Update package repository
sudo apt update && sudo apt upgrade -y
# Install essential development tools
sudo apt install build-essential
# Install GTK+ 3 development packages
sudo apt install gcc pkg-config libgtk-3-dev
# Optional: Install additional development tools
sudo apt install git vim nano
# Verify installation
gcc --version
pkg-config --modversion gtk+-3.0
Expected GTK version: 3.22 or higher
# Update system packages
sudo dnf update -y
# Install development tools group
sudo dnf groupinstall "Development Tools" -y
# Install GTK+ 3 development packages
sudo dnf install gcc pkgconf-pkg-config gtk3-devel
# Verify installation
gcc --version
pkg-config --modversion gtk+-3.0
# Update system
sudo pacman -Syu
# Install base development packages
sudo pacman -S base-devel
# Install GTK+ 3
sudo pacman -S gtk3 pkg-config
# Verify installation
gcc --version
pkg-config --modversion gtk+-3.0
Prerequisites: Install Homebrew if not already installed:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install development tools:
# Install Xcode command line tools (if not already installed)
xcode-select --install
# Install required packages
brew install gcc pkg-config gtk+3
# Install XQuartz for X11 support (required for GTK on macOS)
brew install --cask xquartz
# Verify installation
gcc --version
pkg-config --modversion gtk+-3.0
โ ๏ธ Important for macOS users:
- GTK applications require XQuartz to run properly
- You may need to log out and back in after installing XQuartz
- Consider using
brew install gtk+3instead ofgtk3if you encounter issues
Step 2.1: Download and install MSYS2 from msys2.org
Step 2.2: Launch MSYS2 and update the system:
# Update package database and core system packages
pacman -Syu
# Close terminal when prompted, then reopen and run:
pacman -Su
Step 2.3: Install development tools:
# Install base development tools
pacman -S base-devel
# Install MinGW-w64 toolchain and GTK+ 3
pacman -S mingw-w64-x86_64-gcc mingw-w64-x86_64-pkg-config mingw-w64-x86_64-gtk3
# Optional: Install additional useful tools
pacman -S mingw-w64-x86_64-gdb git nano vim
# Verify installation
gcc --version
pkg-config --modversion gtk+-3.0
Step 2.4: Set up environment:
# Add MinGW64 to your PATH (add to ~/.bashrc for persistence)
export PATH="/mingw64/bin:$PATH"
# Verify the environment
echo $PATH
which gcc
๐ก Windows Alternative: You can also use Code::Blocks with MinGW or Visual Studio with vcpkg, but MSYS2 is recommended for its simplicity and package management.
Before compiling, letโs verify that all components are properly installed:
# Check GCC compiler
gcc --version
# Expected: gcc (GCC) 9.0 or higher
# Check pkg-config
pkg-config --version
# Expected: 0.29 or higher
# Check GTK+ 3 installation
pkg-config --modversion gtk+-3.0
# Expected: 3.22.0 or higher
# List GTK+ compile flags (should show multiple -I include paths)
pkg-config --cflags gtk+-3.0
# List GTK+ linker flags (should show multiple -l library flags)
pkg-config --libs gtk+-3.0
Now letโs compile the calculator application:
# Navigate to the project directory (if not already there)
cd c-gui-calculator
# Compile with basic optimization
gcc -o calculator main.c `pkg-config --cflags --libs gtk+-3.0` -lm
# Check if compilation was successful
ls -la calculator*
# Compile with debugging symbols and warnings
gcc -Wall -Wextra -g -o calculator main.c `pkg-config --cflags --libs gtk+-3.0` -lm
# Or with optimization for release
gcc -O2 -o calculator main.c `pkg-config --cflags --libs gtk+-3.0` -lm
Linux/macOS:
gcc -o calculator main.c `pkg-config --cflags --libs gtk+-3.0` -lm
Windows (MSYS2):
# In MSYS2 MinGW64 terminal
gcc -o calculator.exe main.c `pkg-config --cflags --libs gtk+-3.0` -lm
๐ง Explanation of flags:
-lm: Links the math library (required for mathematical functions)--cflags: Includes compiler flags for GTK+ headers--libs: Includes linker flags for GTK+ libraries-Wall -Wextra: Enables additional compiler warnings-g: Includes debugging information-O2: Enables optimization level 2
# Run the calculator
./calculator
# If you get permission errors, make it executable first:
chmod +x calculator
./calculator
# Run in MSYS2 terminal
./calculator.exe
# Or double-click the calculator.exe file in File Explorer
When successful, you should see:

๐ธ If the calculator doesnโt look right or crashes, see the troubleshooting section below.
pkg-config reports missing paths, verify GTK installation.mingw-w64 environment, not the default msys.If youโve successfully followed this guide, you now have:
Next Steps:
main.c to understand the implementationNeed more help? Check our comprehensive README or create an issue on GitHub.
Happy coding! ๐