Open In App

How to add “graphics.h” C/C++ library to gcc compiler in Linux

While trying c graphic programming on Ubuntu, I figured out that graphic.h is not a standard C library and it is not supported by gcc compiler. So I am writing this article to explain the process.
If you want to use graphics.h on Ubuntu platform you need to compile and install libgraph. It is the implementation of turbo c graphics API on Linux using SDL. 
You can download it from here libgraph
Step by Step Instructions: 
 

sudo apt-get install build-essential
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-2.0 \
guile-2.0-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
./configure
make
sudo make install
sudo cp /usr/local/lib/libgraph.* /usr/lib
int gd = DETECT,gm; 
initgraph (& gd,& gm,NULL);

Example code: 




// C code to illustrate using
// graphics in linux environment
#include<stdio.h>
#include<stdlib.h>
#include<graphics.h>
int main()
{
    int gd = DETECT, gm;
    initgraph(&gd, &gm, NULL);
 
    circle(50, 50, 30);
 
    delay(500000);
    closegraph();
    return 0;
}

Output: 
 

Reference: ask ubuntu 

Important Notes (Added by a user) : Files from the above-given link did not work for me. There are somethings wrong with them I downloaded files from https://github.com/SagarGaniga/Graphics-Library 

 

Article Tags :