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



In this tutorial, we will be discussing a program to understand how to add “graphics.h” C/C++ library to gcc compiler in Linux.

To do this we are required to compile and install the libgraph package.

This includes install build-essential and some external packages

>>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

Then setting the path in the extracted files

>>sudo make install >>sudo cp /usr/local/lib/libgraph.* /usr/lib

Example

#include<stdio.h> #include<stdlib.h> #include<graphics.h> int main(){    int gd = DETECT, gm;    initgraph(&gd, &gm, NULL);    circle(40, 40, 30);    delay(40000);    closegraph();    return 0; }

Output

Updated on: 2020-02-25T07:25:35+05:30

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements