Introduction: Simple Graphic Interface for Linux GCC Compiler

About: Jack passed away May 20, 2018 after a long battle with cancer. His Instructables site will be kept active and questions will be answered by our son-in-law, Terry Pilling. Most of Jack's instructables are tuto…

This is a simple graphic interface for Linux GCC compiler. It is a bash script file using the zenity command. If you don't have zenity and you are using a Debian based system (Ubuntu) it will be in the repositories.

You can install it with the command: sudo apt-get install zenity.

It has been tested in Debian and Ubuntu on a 64 bit system, and Raspian on a RaspberryPi.

Installation:

Create a Directory in you home directory called C.

Download the three files and copy them into your C directory.

c-gui.sh - The script file. Download it and rename it: c-gui.sh

WORKFILE.txt - Holds the name of the program you are working on. Just contains the word "hello"

hello.c - The "Hello World" program. (Just because you need something there to start.)

Make the script file executable with the command: chmod +x c-gui.sh

To run the program open a terminal in your home directory and type: C/c-gui.sh

Step 1: The Code

#!/bin/sh
#Front end for GCC compiler.
#
#


cd C

while [ $# -eq 0 ]
do
    WORK=`cat WORKFILE.txt`
   WFLOADED=1
   WORKC=$WORK".c"

   CHOICE=`zenity --title="GCC" --text="Work File:    "$WORK --height=275 --width=300 \
--list --column="Front End For GCC Compiler" "Create or Select Work FIle" "Edit    "$WORKC "Compile    "$WORKC "Test Run    "$WORK "Terminal" "Exit"`
   if [ "$CHOICE" = "Create or Select Work FIle" ]; then
      TEMP=`zenity --entry --entry-text="Currently:  "$WORK --width=300`
      if [ $WFLOADED -gt 0 ]; then
         WORK=$TEMP
         WORKC=$WORK".c"
         echo $WORK > WORKFILE.txt 
      fi
   fi
   if [ "$CHOICE" = "Edit    "$WORKC ]; then
      if [ $WFLOADED -gt 0 ]; then
         gedit $WORK".c"
      else
         zenity --info --text="Work file is empty, create or select a work file." --timeout=2
      fi
   fi
   if [ "$CHOICE" = "Compile    "$WORKC ]; then
      if [ $WFLOADED -gt 0 ]; then
         clear
         gcc $WORK".c" -lm
         mv -f a.out $WORK
      else
         zenity --info --text="Work file is empty, create or select a work file." --timeout=2
      fi
   fi
   if [ "$CHOICE" = "Test Run    "$WORK ]; then
      if [ $WFLOADED -gt 0 ]; then
         echo " " 
         ./$WORK
         echo " "
         echo -n "Press  to continue: "
         read WORKHOLD
         clear
      else
         zenity --info --text="Work file is empty, create or select a work file." --timeout=2
      fi
   fi
   if [ "$CHOICE" = "Terminal" ]; then
      gnome-terminal
   fi
   if [ "$CHOICE" = "Exit" ]; then
      exit 0
   fi
done

Step 2: Program Notes

Some versions of zenity will perform the menu selection when you double click on it. Other versions require you to click the selection and then click the Okay button.

In the "Create or Select Work File" option You enter the program name without the ".c" extension. If you choose this option and then don't enter anything you will get an error message.

You will probably want to modify some of the menu selections to better suit your style:

You may change the line of code that calls the editor to your editor of choice. Mine is gedit.

You can add any compiler directives or link libraries to the line that calls GCC.

The terminal that you call g-gui.sh from remains open, but you don't have access to it. It is used to display error messages from the compiler.

The "Terminal" option opens a terminal that you can use. You may need to change the name of the terminal to the default terminal program for your distro. Since I am using Ubuntu to write this my default terminal is "gnome-terminal".