For using graphics.h library in Ubuntu, you need to follow few simple steps given below:
First of all, you need to install few packages. For that, run command this on your terminal “sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev”
Next you need to install libgraph package. Download libgraph-1.0.2.tar.gz from link:
download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz
Extract this where you want. Now navigate to the folder, where you just extracted your libgraph-1.0.2.tar.gz using cd command. Run these commands on your terminal.
> cd libgraph-1.0.2
> ./configure
>sudo make
> sudo make install
> sudo cp /usr/local/lib/libgraph.* /usr/lib
And if you got error message “configure: error: *** SDL version 1.2.0 not found!”, try installing it using: “sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev”
Another error which you can get is: “configure: cannot find guile-config; is Guile installed?” Solve this by using command“sudo apt-get install guile guile-dev”.
If this didn’t helped much, then we have another way to get it work in right way. Use synaptic package manager to install related files.
Now try compliling your C program.
#include<stdio.h>
#include<graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
int i,x=10;
char str[3]=”0″;
setbkcolor(BLUE);
setcolor(12); //outline heart
circle(50,50,40);
circle(110,50,40);
line(22,80,80,140);
line(80,140,138,80);
floodfill(50,50,12); //fill heart
floodfill(110,50,12);
floodfill(80,50,12);
floodfill(80,100,12);
getch();
closegraph();
return 0;
}
First of all, you need to install few packages. For that, run command this on your terminal “sudo apt-get install libsdl-image1.2 libsdl-image1.2-dev guile-1.8 guile-1.8-dev”
Next you need to install libgraph package. Download libgraph-1.0.2.tar.gz from link:
download.savannah.gnu.org/releases/libgraph/libgraph-1.0.2.tar.gz
Extract this where you want. Now navigate to the folder, where you just extracted your libgraph-1.0.2.tar.gz using cd command. Run these commands on your terminal.
> cd libgraph-1.0.2
> ./configure
>sudo make
> sudo make install
> sudo cp /usr/local/lib/libgraph.* /usr/lib
And if you got error message “configure: error: *** SDL version 1.2.0 not found!”, try installing it using: “sudo apt-get install libsdl1.2-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev”
Another error which you can get is: “configure: cannot find guile-config; is Guile installed?” Solve this by using command“sudo apt-get install guile guile-dev”.
If this didn’t helped much, then we have another way to get it work in right way. Use synaptic package manager to install related files.
Now try compliling your C program.
#include<stdio.h>
#include<graphics.h>
int main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,NULL);
int i,x=10;
char str[3]=”0″;
setbkcolor(BLUE);
setcolor(12); //outline heart
circle(50,50,40);
circle(110,50,40);
line(22,80,80,140);
line(80,140,138,80);
floodfill(50,50,12); //fill heart
floodfill(110,50,12);
floodfill(80,50,12);
floodfill(80,100,12);
getch();
closegraph();
return 0;
}