Let us learn how to download and install Graphics.h in Ubuntu operating system. This step by step guide will enable you to install graphics.h package libgraph in Linux Ubuntu OS.
If you want to execute C programs with graphics.h in Ubuntu, you will have to compile and install libgraph package.
What is graphics.h header file?
The graphics.h header file is used to display different kinds of visualisations in C programming.
It can help display 2-dimensional images, different types of fonts, animations and much more on the graphical side.
There are different pre-defined functions available in graphics.h header file such as:
- drawImage(filename, x, y)
- initGraphics(width, height)
- drawLine(x0, y0, x1, y1)
- drawArc(x, y, width, height, start, sweep)
- drawRect(x, y, width, height)
- fillArc(x, y, width, height, start, sweep)
- drawOval(x, y, width, height)
What is libgraph package?
The libgraph package is a simple and easy 2-dimensional graphics interface used to perform visualisations. It is also known as WinBGIM library.
The libgraph library is an implementation of the Turbo C graphics API which is graphics.h on Linux using Simple DirectMedia Layer (SDL).
If you encounter SDL version 1.2.0 not found error, visit Simple DirectMedia Layer official website. Please find how to install SDL library in Ubuntu at the bottom.
The GNU GCC compiler, which is the default C and C++ Compiler in Ubuntu does not include graphics.h header file in its directory by default.
So, the inclusion of the preprocessor directive #include<graphics.h> does not work. It will give an error – graphics.h not found in Ubuntu.
Therefore, we need to know how to add graphics.h in Ubuntu OS to enable graphics in C programming language.
The graphics.h is a header file in C programming that helps you to include methods related to graphics in your C Program.
In addition to the graphics.h library in C programming, there are many libraries that offer functionalities to develop graphics programs in Linux.
The libgraph library, to be frank, is an age-old library. You must use the latest graphics libraries such as OpenGL, which is a high-performance graphics library.
How To Run Graphics.h in Linux Ubuntu?
In short, download and copy the libgraph-1.0.2.tar.gz to your USR directory. Extract it and run your C program with #include<graphics.h> statement. Find step by step guide below.
Output

Steps to Install graphics.h in Ubuntu in C programming
1. Download libgraph package file for Ubuntu operating system
Click on the button to download libgraph package for Ubuntu operating system.
2. Install build-essentials
1 | sudo apt-get install build-essential |
3. Install packages to run graphics.h header file
You need to install an entire list of packages which can be executed in a single statement as follows.
1 | 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 libgraph.tar.gz package file
You can extract a file in Linux using two methods:
- Right-click on the compressed file and extract it in the same folder
- Execute a Linux command to untar the libgraph file
1 | tar -xvzf libgraph.tar.gz |
5. Copy extracted libgraph folder into USR directory
1 | sudo cp -r libgraph-1.0.2 /usr/local/lib |
6. Compile a C program with graphics.h header file
The following line of code will help you to understand how to compile graphics.h in Ubuntu 14.04 operating system.
1 | gcc test.c -lgraph |
Note: This graphics C program is compiled with GNU GCC compiler on Ubuntu 14.04 operating system. However, these codes are compatible with all other operating systems.
How To Install SDL Library in Linux Ubuntu?
It is very easy to download and install the SDL graphics library in your Ubuntu operating system. Please follow the steps below.
Step 1: Start your Linux terminal and type the following command.
1 | sudo apt-get install libsdl2-dev |
Step 2: Run your C program with the following statement.
1 | gcc armstrong_number.c -lSDL2 |
Sample Graphics Program in C Programming Language
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #include<stdio.h> #include<conio.h> #include<graphics.h> int main() { int gd = DETECT, gm; int left = 100, right = 200, top = 100, bottom = 200; printf("\nLet's build a sample rectangle using Graphics in C\n"); initgraph(&gd, &gm, "C:\\TC\\BGI"); rectangle(left, top, right, bottom); getch(); closegraph(); return 0; } |
Let’s discuss more on how to install graphics.h in Ubuntu OS in the comment section below if you have any compilation errors or doubts about the same.
The Libgraph package is too old. OpenGL is very much in demand and you people should use it for graphics in C Programming.
Hi! I got an Error! It says – “configure: error: *** SDL version 1.2.0 not found!”. Please help.
This is another very common error that I found very often while installing graphics.h package in my Linux ubuntu machine. To solve this, you need to type the following command in your Linux Terminal:
sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev
This sill install some important and related packages.
Thanks. I am able to run graphics libraries in my Linux Mint now.
I am getting the following error while installing Graphics Libgraph package. It says – “cannot find guile-config”.
Try the following command in your Linux Terminal. It will install guile package in your Ubuntu machine.
sudo apt-get install guile guile-dev
In the above paragraph, you have mentioned about GLUT. Can you tell me how to download it in linux ubuntu?
Okay. You can download and install GLUT in Ubuntu via Ubuntu Terminal using the following command:
sudo apt-get install freeglut3-dev
What is build essential used for?
The Build Essential is a reference for other packages. It is a meta package which contains tools and softwares such as G++, GCC and many others to compile and build other softwares from cratch.
The graphics.h library is deprecated now I think, especially in Ubuntu.
Amazing solution. Now, I can easily compile and run graphics programs in C language.
I am getting a error which says “you have held broken packages” when i try to Install Packages To Run Graphics.h Header File.?What should I do?.
tried alot always getting same error on ubuntu 16.10
the code complies but gives this error while executing and aborts
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
demo: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost’ failed.
It worked fine for me on Ubuntu 14 version. Did you check stackoverflow?
Yes checked out throughout but all I found was same question but not solution they just suggested different alternatives like openly.
But I can’t for it as it has to be performed using graphics.h for practical exam
I followed all step by step installation from various site but all stated the same and didn’t even faced any issues while installing libgraph and dependencies
rocessing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
demo: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost’ failed.
I cannot use the ‘sudo apt-get install ‘command since i am facing trouble with my drivers and hence unable to connect to the internet. So, how can i install ‘ graphics.h’ and its build essentials without internet?
Try using sudo apt-get update first. It will update all your Ubuntu drivers. Then, try this command. You need to have to connect to the internet to install graphics.h.
I have got an error saying : -Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
libsdl1.2-dev : Depends: libsdl1.2debian (= 1.2.15-8ubuntu1) but 1.2.15-8ubuntu1.1 is to be installed
Depends: libpulse-dev but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
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
Reading package lists… Done
Building dependency tree
Reading state information… Done
Note, selecting ‘guile-1.8-dev’ for regex ‘guile-1.8’
Package guile-1.8-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
E: Package ‘guile-1.8-dev’ has no installation candidate
why i can’t install libsdl- 🙁
I want to download WinBGIM graphics library. Can you please help me with that?
I installed libgraph-1.0.1.tar.gz and its working fine as well!
Does the Libgraph and graphics.h work in Linux Fedora and other distributions as well?
I am facing this error: configure: cannot find guile-config.
Please help me ASAP.
Please type this command on the Ubuntu terminal and let us know if this resolved your issues:
sudo apt-get install guile guile-dev
The libgraph library and overall graphics.h package is dead now. You might be able to manage somehow and run your C programs consisting of graphics but it’s not supported by most of the compilers and IDEs.
I would suggest that there are so many other good alternatives to graphics.h which you can definitely make use of. I have enlisted few of them below:
1. SDL(Already mentioned above)
2. GLFW
3. Simple and Fast Multimedia Library (SFML)
4. Allegro
5. Cinder
I also highly recommend you guys to use Visual Studio C compiler.
I’d say that SDL_bgi is much better than libgraph: it’s SDL2-based, more portable, and *much* faster than libgraphh. http://libxbgi.sourceforge.net/
I am getting a error which says “you have held broken packages” when i try to Install Packages To Run Graphics.h Header File.?What should I do?.
Hi
I got the error even after installing graphics.h
fatal error: graphics.h: No such file or directory
compilation terminated.
What should i do?