C GUI Calculator

A GUI-based calculator developed in C using GTK.


Project maintained by rafisarkar0128 Hosted on GitHub Pages — Theme by mattgraham

๐Ÿ’ก Getting Started โ€“ C GUI Calculator

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.

๐ŸŽฏ What Youโ€™ll Learn

By following this guide, you will:

๐Ÿ“ฆ Prerequisites & System Requirements

Essential Components

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

System Requirements

๐Ÿ“‹ Note: See our detailed Requirements Guide for comprehensive package information and alternative installation methods.

๐Ÿš€ Step-by-Step Setup & Compilation

๐Ÿ”น Step 1: Clone the Repository

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

๐Ÿ”น Step 2: Install Development Dependencies

Choose the appropriate instructions for your operating system:

๐Ÿ“ Linux (Debian/Ubuntu/Mint)

# 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

๐Ÿ“ Linux (Fedora/CentOS/RHEL)

# 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

๐Ÿ“ Linux (Arch/Manjaro)

# 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

๐Ÿ“ macOS (Homebrew)

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+3 instead of gtk3 if 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.

๐Ÿ”น Step 3: Verify Your Development Environment

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

๐Ÿ”น Step 4: Compile the Calculator

Now letโ€™s compile the calculator application:

Basic Compilation

# 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

Platform-Specific Compilation Notes

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

๐Ÿ”น Step 5: Run the Calculator

Linux/macOS:

# Run the calculator
./calculator

# If you get permission errors, make it executable first:
chmod +x calculator
./calculator

Windows (MSYS2):

# Run in MSYS2 terminal
./calculator.exe

# Or double-click the calculator.exe file in File Explorer

Expected Behavior

When successful, you should see:

  1. A calculator window opens with a clean, modern interface
  2. Number buttons (0-9), operation buttons (+, -, *, /, ^)
  3. Scientific function buttons (sin, cos, tan, sqrt, log, ln)
  4. A display showing โ€œ0โ€ initially
  5. Responsive button clicks and keyboard shortcuts (Enter, Backspace)

Calculator Interface

๐Ÿ“ธ If the calculator doesnโ€™t look right or crashes, see the troubleshooting section below.

๐Ÿ› ๏ธ Troubleshooting

๐Ÿ“š Additional Resources & References

Official Documentation

Platform-Specific Resources

Learning Resources

Development Tools

Community & Support


๐ŸŽ‰ Congratulations!

If youโ€™ve successfully followed this guide, you now have:

Next Steps:

  1. Explore the calculatorโ€™s features and test different mathematical expressions
  2. Read through the source code in main.c to understand the implementation
  3. Try modifying the code to add new features or customize the interface
  4. Share your experience or contribute improvements to the project

Need more help? Check our comprehensive README or create an issue on GitHub.

Happy coding! ๐Ÿš€