Before using graphic.h in your program we have install few libraries and packages which enable us to compile graphic.h library in linux

Step 1
Install basic compilers for that you need the build-essential package. For this run:
sudo apt-get install build-essential

Step 2
Now install libraries

  • sudo apt-get install libsdl-image1.2
  • sudo apt-get install libsdl-image1.2-dev
  • sudo apt-get install guile-1.8
  • sudo apt-get install guile-1.8-dev
  • sudo apt-get install libsdl1.2debian
  • sudo apt-get install libart-2.0-dev
  • sudo apt-get install libaudiofile-dev
  • sudo apt-get install libesd0-dev
  • sudo apt-get install libdirectfb-dev
  • sudo apt-get install libdirectfb-extra
  • sudo apt-get install libfreetype6-dev
  • sudo apt-get install libxext-dev
  • sudo apt-get install x11proto-xext-dev
  • sudo apt-get install libfreetype6
  • sudo apt-get install libaa1
  • sudo apt-get install libaa1-dev
  • sudo apt-get install libslang2-dev
  • sudo apt-get install libasound2
  • sudo apt-get install libasound2-dev

Step 3:
Now download libgraph and extract it to home folder. Now run commands one by one

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

Step 4:
Program:

#include<iostream>
#include<graphics.h>
using namespace std;
int main()
{
/* gd detect will detect the present graphic driver in your system automatically and gm is graphics mode sets highest resolution for detected driver  */
int gd=DETECT,gm,x,y;
initgraph(&gd,&gm,NULL);
line(60,10,100,100);
getch();
closegraph();
return 0;
}

Compile it with : g++ abc.cpp -lgraph amd run with it ./a.out

Advertisements