Graphics.h c++ undefined reference to various functions like line(),initgraph()
16,980
Change
initgraph(&gd,&gm,"");
to
initgraph(&gd,&gm,NULL);
for compiling:
g++ -o filename filename.cpp -lgraph
to execute:
./filename
Author by
Adit Jain
Python, C , Algorithms. Hope to contribute more than just questions :D.
Updated on August 03, 2022Comments
-
Adit Jain almost 2 years
#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
undefined reference to 'initgraph'
undefined reference to 'closegraph'
undefined reference to 'line'[4 times]
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.
-
AurumTechie almost 3 yearsNot working for me. I get an error. C:/Program Files/CodeBlocks/MinGW/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: cannot find -lgraph collect2.exe: error: ld returned 1 exit status. Please help me.