简体   繁体   中英

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

#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.

Change

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

to

initgraph(&gd,&gm,NULL);

for compiling:

g++ -o filename filename.cpp -lgraph

to execute:

./filename

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM