How To Install and Run Graphics.h in Ubuntu

By | October 13, 2016

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:

  1. drawImage(filename, x, y)
  2. initGraphics(width, height)
  3. drawLine(x0, y0, x1, y1)
  4. drawArc(x, y, width, height, start, sweep)
  5. drawRect(x, y, width, height)
  6. fillArc(x, y, width, height, start, sweep)
  7. 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.


Install and Run graphics.h in Ubuntu and download libgraph for GCC compiler in Linux Ubuntu

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

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.

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

5. Copy extracted libgraph folder into USR directory

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.

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.

Step 2: Run your C program with the following statement.

Sample Graphics Program in C Programming Language

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.

30 thoughts on “How To Install and Run Graphics.h in Ubuntu

  1. Ajit Shukla

    The Libgraph package is too old. OpenGL is very much in demand and you people should use it for graphics in C Programming.

  2. Mahesh Karandikar

    Hi! I got an Error! It says – “configure: error: *** SDL version 1.2.0 not found!”. Please help.

    1. Ajay Sawant

      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.

  3. Krishna Kunal

    Thanks. I am able to run graphics libraries in my Linux Mint now.

  4. Vishal Upadhyay

    I am getting the following error while installing Graphics Libgraph package. It says – “cannot find guile-config”.

    1. Ajay Sawant

      Try the following command in your Linux Terminal. It will install guile package in your Ubuntu machine.
      sudo apt-get install guile guile-dev

  5. Prasad Kulkarni

    In the above paragraph, you have mentioned about GLUT. Can you tell me how to download it in linux ubuntu?

    1. Tushar Soni Post author

      Okay. You can download and install GLUT in Ubuntu via Ubuntu Terminal using the following command:
      sudo apt-get install freeglut3-dev

  6. Vikas Bahl

    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.

  7. Shekhar Rao

    The graphics.h library is deprecated now I think, especially in Ubuntu.

  8. Siddhant Awasthi

    Amazing solution. Now, I can easily compile and run graphics programs in C language.

  9. Anonymous

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

  10. shivam

    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.

  11. Mohit Agarwal

    It worked fine for me on Ubuntu 14 version. Did you check stackoverflow?

    1. Shivam

      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

  12. honey

    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.

  13. Anonymous

    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?

  14. Ankita Srivastav

    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.

  15. Anonymous

    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.

  16. Nguyễn Thành Quang

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

  17. Akash Aware

    I want to download WinBGIM graphics library. Can you please help me with that?

  18. Saniya Ahuja

    I installed libgraph-1.0.1.tar.gz and its working fine as well!

  19. Vijay Dasari

    Does the Libgraph and graphics.h work in Linux Fedora and other distributions as well?

  20. Guru Randhawa

    I am facing this error: configure: cannot find guile-config.
    Please help me ASAP.

    1. Tushar Soni Post author

      Please type this command on the Ubuntu terminal and let us know if this resolved your issues:
      sudo apt-get install guile guile-dev

  21. Maha Al - Shawani

    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.

  22. Harsh Maithia

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

  23. Snehal

    I got the error even after installing graphics.h
    fatal error: graphics.h: No such file or directory
    compilation terminated.
    What should i do?


Let's Discuss