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
#include<graphics.h>

using namespace std;
 
int main()
 {
  system("clear"); 
  int gmode, gdriver=DETECT;
  initgraph(&gdriver,&gmode, NULL);
  circle(100, 100, 50);
  delay(5000);
  closegraph();
  return 0;
 }

and compile it with the command:

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

and see here is the awaited output:

Bloggraphicsh

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!

 

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Google+ photo

You are commenting using your Google+ 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 )

w

Connecting to %s