Graphics.h in Linux for C and C++
Most of the students in Windows use graphics.h header file in there programs that are written in TurboC. This is a reason that some don’t wanna migrate to Linux well there is a solution for that to. Just follow the steps that i did in Ubuntu..
First run sudo apt-get build-essential to install necessary compiler tools.
Then, install the following packages:
libsdl-image1.2
libsdl-image1.2-dev
guile-1.8
guile-1.8-dev
libsdl1.2debian-arts
libartsc0-dev
libaudiofile-dev
libesd0-dev
libdirectfb-dev
libdirectfb-extra
libfreetype6-dev
libxext-dev
x11proto-xext-dev
libfreetype6(upgrade)
libaa1
libaa1-dev
libslang2-dev
libasound2
libasound-dev
You can install them via Synaptic Package Manager (System/Administration/) one by one. or type the following command in the terminal :
sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev libsdl1.2debian-arts libartsc0-dev libaudiofile-dev libesd0-dev libdirectfb-dev libdirectfb-extra libfreetype6-dev libxext-dev x11proto-xext-dev libfreetype6(upgrade) libaa1 libaa1-dev libslang2-dev libasound2 libasound-dev
After this download libgraph-1.0.1 (This is the link) to your Home Folder.
Right click on it and press “Extract here”
Now type in the terminal
./configure
sudo make
sudo make install
This completes the installation.
Now just add the following lines in your program:
int gd,gm=VGAMAX; gd=DETECT;
initgraph(&gd,&gm,NULL);
and compile using g++ like:
g++ test.cpp -o test.o -lgraph
And execute the program by ./test.o
If on compile it gives u an error that says “could not load shared libraries” or something like that just run the following command and it should fix it
sudo cp /usr/local/lib/libgraph.* /usr/lib
An example program(to print a rectangle) :
#include
#include
int main(void)
{
int gd=DETECT, gm=VGAMAX;
initgraph(&gd, &gm, 0);
moveto(0, 0);
rectangle(50,50,500,200);
while (!kbhit());
closegraph();
return 0;
}
If there are any problems please leave a comment.














Way to go !!
Though I am finding it difficult to read. This is for young eyes!!
OMFG. You don’t even give credit to the person you stole all this from. And you call this blogging. Funny.
Well sorry about dis one.. i 4got to add it.
Its not from a particular source but a group of sources combined..
Nice, i used to work on borland C (old i know) but in the school is the only way to make programs.
This post helps me a lot, i like colors in my linux programs xD.
Its a shame that you steal content, nah just kidding.
good work man……uve messed up hard with linux….gr8 hacks….
Thanxs man…
Can you help me in displaying a bmp image in linux platform using c?
Thanks, it works excellent!..
But I have not found the kbhit() function in the graphics.h or library. All variants of kbhit() found using Google worked for me not.
Did you like to show your kbhit() version or a library which contais it?
Hey!
Thanx for the post, what happens with me is that I get this error message:
graphix.cpp: In function ‘int main(int, char**)’:
graphix.cpp:39: error: ‘kbhit’ was not declared in this scope
what is kbhit I guess keyboard hit but how do I define it?
Thanx!