Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphics.h c++ undefined reference to various functions like line(),initgraph()

Tags:

c++

line

bgi

#include<graphics.h>
#include<stdio.h>

main()
{
int gd=DETECT,gm;
int i,x,y;
initgraph(&gd,&gm,"");
line(0,0,640,0);
line(0,0,0,480);
line(639,0,639,480);
line(639,479,0,479);
for(i=0;i<=1000;i++)
{
   x=rand()%639;
   y=rand()%480;
   putpixel(x,y,15);
}
  getch();
  closegraph();
}

The Following is a Basic Graphic Program,It Shows the Errors as

  1. undefined reference to 'initgraph'

  2. undefined reference to 'closegraph'

  3. undefined reference to 'line'[4 times]

  4. undefined reference to 'putpixel'

    Compiler : CodeBlocks; Language:c++;


I Have Copied the graphics.h and winbgim.h in include folder and the libbgi.a in the lib folder also i have linked all the libraries required to be linked. Please Help.

like image 948
Adit Jain Avatar asked Jul 18 '15 07:07

Adit Jain


People also ask

What is Initgraph computer graphics?

initgraph initializes the graphics system by loading a graphics driver from disk (or validating a registered driver), and putting the system into graphics mode. To start the graphics system, first call the initgraph function. initgraph loads the graphics driver and puts the system into graphics mode.

Why Graphics h is not working in VS code?

This is because graphics. h runs is not available in the library folder of CodeBlocks. To successfully compile graphics code on CodeBlocks, setup winBGIm library.

How do I run a graphics program in Visual Studio code C++?

In Visual Studio, on the main menu, choose Debug, Graphics, Start Graphics Debugging, or just press Alt+F5. This starts your app under Graphics Diagnostics and displays the diagnostics session windows in Visual Studio.


1 Answers

Change

initgraph(&gd,&gm,"");

to

initgraph(&gd,&gm,NULL);

for compiling:

g++ -o filename filename.cpp -lgraph

to execute:

./filename
like image 81
Tushar Nitave Avatar answered Sep 27 '22 23:09

Tushar Nitave