How to run graphics.h in Ubuntu using g++

Aaah… I was just now wondering while running a program on Ubuntu terminal using g++ because the program included graphics.h and by default, it wasn’t available for g++ in the system. So my query was to run a graphics.h required a program on the terminal. And the question is finally resolved if you are facing the similar problem? thenIt is specifically for Ubuntu 16.04 LTS

To use graphics.h in Ubuntu we’ll need to install and extract something called “libgraph” it is actually the turbo C graphics API implementation on Linux using SDL.

you may download the “libgraph” from Here.

Now proceed as follows:- you simply copy and paste as well.

$ sudo apt-get install build-essential
$ 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

Now your build-essentials are installed with other different packages needed for the process.

  • Now extract the downloaded filelibgraph-1.0.2.tar.gz by going to the directory where the file is downloaded. like
$ cd Downloads/
$ tar xvzf libgraph-1.0.2.tar.gz

Here x: to extract, v: for verbose, z: to uncompress, f: it tells the command that after this you are going to give a specific file name to extract. okay? Now, after the extraction will be done. Move to the extracted folder. and proceed as follows.

$ cd libgraph-1.0.2/
$ ./configure
$ make
$ sudo make install
$ sudo cp /usr/local/lib/libgraph.* /usr/lib

Now you are all set ladies and gentlemen, to run your graphics.h programs on g++. let’s see, my simple example:-  you may use any other text editor as well.

$ vim test.cpp

using namespace std;
int main()
  int gmode, gdriver=DETECT;
  initgraph(&gdriver,&gmode, NULL);
  circle(100, 100, 50);
  return 0;

and compile it with the command:

$ g++ -o test.exe test.cpp -lgraph
$ ./test.exe

and see here is the awaited output:


Alright, then It is working ok!

thanks for reading I hope you learned something new.

see you next time, till then be a smart learner and this, is GeekyShacklebolt

bidding you goodbye!


One thought on “How to run graphics.h in Ubuntu using g++

  1. I wrote SDL_bgi exactly to provide a portable ‘GRAPHICS.H’ implementation that is compatible with the original Borland compiler for DOS. It can be downloaded from

    To compile and install it on any GNU/Linux distro, do:

    $ tar zxvf SDL_bgi-2.4.4.tar.gz # or later release
    $ cd SDL_bgi-2.4.4/src
    $ make
    $ sudo make install

    Files will be installed in appropriate directories:

    SDL_bgi.h -> /usr/include/SDL2/
    graphics.h -> /usr/include/ -> /usr/lib/

    To compile a graphics program with SDL_bgi:

    $ gcc -o program program.c -lSDL_bgi -lSDL2

    Happy graphics programming!

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s