Install and Run Graphics.h in Ubuntu OS (Complete Tutorial)
Learn How To Install and Run Graphics.h in Ubuntu Operating System. Install Graphics Package Libgraph in Linux Ubuntu OS.
The GNU GCC Compiler which is the default C and C++ Compiler in Ubuntu does not include graphics header files in its directory. Therefore, the inclusion of the preprocessor directive #include<graphics.h> will not work. It will give an error saying graphics.h not found.
The graphics.h is a Header File in C Programming that helps you to include functions related to graphics in your C Program.
By default, the Graphics Header File <graphics.h> does not work in Ubuntu for C and C++ Programming. We need to explicitly install the graphics package Libgraph to enable Graphics in C Programming.
1. Download Libgraph File
Download Graphics Package For Ubuntu Here: Libgraph
2. Install Build Essentials
sudo apt-get install build-essential
3. Install Packages To Run Graphics.h Header File
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
4. Extract the File
You can extract a file in linux using two methods:
a. Right click on the compressed file and extract it in the same folder
b. Execute a Linux command to untar the Libgraph file
tar -xvzf libgraph.tar.gz
5. Copy Extracted Libgraph Folder into USR Directory
sudo cp -r libgraph-1.0.2 /usr/local/lib
6. Compile A C Program with Graphics Header File
gcc test.c -lgraph
There are many libraries other than Libgraph to develop graphics programs in Linux. Libgraph is an old library. You should try your hands on OpenGL which is a high performance graphics library.
Sample Graphics Program in C Language
int gd = DETECT, gm;
initgraph(&gd, &gm, "");
circle(335, 335, 250);
If you have any compilation errors or doubts in installing graphics.h header files in Ubuntu, let us know about it in the comment section below.