How to Run C AND C++ Graphics Program in Linux

Run "graphics.h" in Ubuntu

        This post is about how you can run graphics program in Ubuntu platform. Generally we run graphics program in Turbo C on windows platform. If you are addicted to gcc compiler then it is not providing inbuilt facility to run graphics.h library. So you are not able to run graphics in C language, to run "graphics.h" library in Ubuntu, following are some simple steps.

Watch on YouTube :


Make sure that you have basic compilers installed. For this run the command:
     sudo apt-get install build-essential

Install few packages that required. Run the command:
     sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian libart-2.0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6 libaa1 libaa1-dev libslang2-dev libasound2 libasound2-dev

Now download libgraph.
Copy libgraph-1.0.2.tar.gz to your home folder. Right click on it and select "Extract Here".
Then run following commands one by one.
     cd libgraph-1.0.2
     sudo make
     sudo make install
     sudo cp /usr/local/lib/libgraph.* /usr/lib

Now Ubuntu is ready to run graphics program. To do that add #include<graphics.h> in your C program.

>>In Turbo C we use following lines
     int gd=DETECT,gm; 
>>In Ubuntu instead of "c:\\tc\\bgi" write NULL
     int gd=DETECT,gm; 
Here is a sample program to test it's working or not. sample.c
Run it with following command:
     gcc sample.c -o sample -lgraph
If you get following screen then my job is done.

Last modified: Friday, 29 July 2016, 10:03 AM