LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-11-2005, 09:47 AM   #1
pankaj_iiitian89
LQ Newbie
 
Registered: Sep 2005
Location: lucknow
Posts: 8

Rep: Reputation: 0
problem with graphics.h


i have got gnu compiler and i have bgi library and header files in proper places..but when i compiled a program which has included graphics.h ...it gave the following error..
MY program was


#include<iostream>
#include<graphics.h>
using namespace std;
int main(){
int driver=DETECT,mode; // initializing drivers
initgraph(&driver,&mode,"\\tc\\bgi");
struct cord{ // structure for points representation
int x;
int y;
}a[10],b,seek;
int n,ymax=0,x=0,y,i;
double m; // for slope
cout<<"enter the no. of vertices in your polygon\n(avoid line of infinite slope) : ";
cin>>n;
for(i=0;i<n;i++){ // loop for entering edges
cout<<"enter x"<<i+1;
cout<<"and y"<<i+1<<'\t';
cin>>a[i].x>>a[i].y;
}

for(i=0;i<n;i++) { // calculating maximum value of y-coordinate
if(ymax<a[i].y)
ymax=a[i].y;
}

for(i=0;i<n;i++) //polygon creation
line(a[i].x,a[i].y,a[(i+1)%n].x,a[(i+1)%n].y);
cout<<"enter the point to tested : ";
cin>>b.x>>b.y;
seek.x=b.x;
seek.y=ymax+1; //reference point parallel to y-axis

for(i=0;i<n;i++){ // counting no.of edges intersecting the reference line
if(b.x>a[i].x&&b.x<a[(i+1)%n].x||b.x<a[i].x&&b.x>a[(i+1)%n].x){
m=(double)(a[(i+1)%n].y-a[i].y)/(a[(i+1)%n].x-a[i].x);
y=a[i].y+m*(seek.x-a[i].x);
if(y<seek.y&&y>=b.y)
x++;
}
else if(b.x==a[i].x){ //checking for condition when reference line passes through any vertex
m=(double)(a[(i+1)%n].y-a[i].y)/(a[(i+1)%n].x-a[i].x);//slope
y=a[i].y+m*(seek.x-a[i].x);
if(y<seek.y&&y>b.y)
x++;
}
}

if(x%2==0)
cout<<"the point is exterior to polygon";
else
cout<<"the point is interior to polygon";
putpixel(b.x,b.y,8); //print the point to test
circle(b.x,b.y,1); // for highlihting the test point
closegraph();
return 0;
}

i got the following errors:


/tmp/ccwbBm5y.o(.text+0x2c): In function `main':
: undefined reference to `initgraph(int*, int*, char*)'
/tmp/ccwbBm5y.o(.text+0x1de): In function `main':
: undefined reference to `line(int, int, int, int)'
/tmp/ccwbBm5y.o(.text+0x531): In function `main':
: undefined reference to `putpixel(int, int, int)'
/tmp/ccwbBm5y.o(.text+0x544): In function `main':
: undefined reference to `circle(int, int, int)'
/tmp/ccwbBm5y.o(.text+0x54c): In function `main':
: undefined reference to `closegraph()'
collect2: ld returned 1 exit status



can anyone please sort out my problem and what should i do for the same..
 
Old 09-11-2005, 02:06 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
You need to add a linker flag to include the bgi libraries when you link the program together. Otherwise, you are just providing the header files (i.e. telling the compiler that the library will be provided) but not providing the library itself.

If the library is called /usr/lib/libbgi.so then you would add -lbgi to the compiler's command-line. See the BGI library documentation, and the GCC manual, for more details.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Graphics problem anjum Linux - Hardware 1 04-17-2005 05:49 PM
Graphics problem steamfamous Linux - Newbie 3 01-04-2005 07:21 PM
Graphics problem TheViking Linux - Hardware 14 04-25-2003 01:50 AM
Graphics Problem jasonk Linux - Newbie 1 10-27-2002 11:56 PM
Graphics problem... jasonk Linux - General 3 10-27-2002 08:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration