나는 C++ 및 OpenGL 개발을 배우고 MFC 기반의 튜토리얼을 따라야했지만 gcc로 리눅스로 변환하려고 시도했다.gcc/C++ - 정의되지 않은 참조/클래스 오류
대부분 성공하지만, 컴파일 할 때이 오류가 발생합니다.
/tmp/ccUmEDkj.o: In function `display()':
14new.cc:(.text+0x1ee): undefined reference to `Titik2D::shearing(Titik2D, int)'
collect2: error: ld returned 1 exit status
이것은 어떻게 컴파일하나요?
gcc 14new.cc -lGL -lglut -lGLU -o 14
14new.cc
#include <stdio.h>
#include <GL/freeglut.h>
GLsizei wh = 600 ; // initial height of window
GLsizei ww = 800 ; // initial width of window
class Titik2D {
public: int x,y;
Titik2D shearing(Titik2D p, int h);
};
Titik2D shearing(Titik2D p, int h)
{
Titik2D temp;
temp.x=p.x + h*p.y;
temp.y=p.y;
return temp;
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT); //clear pixel buffer
Titik2D hit;
int i;
Titik2D p[11], q[11];
p[0].x=10; p[0].y=10;
p[1].x=50; p[1].y=10;
p[2].x=50; p[2].y=100;
p[3].x=100; p[3].y=100;
p[4].x=100; p[4].y=150;
p[5].x=50; p[5].y=150;
p[6].x=50; p[6].y=250;
p[7].x=150; p[7].y=250;
p[8].x=150; p[8].y=300;
p[9].x=10; p[9].y=300;
p[10].x=10; p[10].y=10;
glColor3f(1,0,0);
glBegin(GL_LINE_STRIP);
for (i=0; i<= 10; i++)
glVertex2i(p[i].x, p[i].y);
glEnd();
for (i=0; i<= 10; i++){
q[i]= hit.shearing(p[i],2);
}
glBegin(GL_LINE_STRIP);
for (i=0; i <=10; i++)
glVertex2i(q[i].x, q[i].y);
glEnd();
glFlush();
}
void MyInit (void) {
glClearColor (1.0, 1.0, 1.0, 0.0); //white background
glColor3f(1, 0, 0); // red drawing colour
glMatrixMode (GL_PROJECTION);
glLoadIdentity();
gluOrtho2D (0.0, (GLdouble)ww, 0.0, (GLdouble)wh); //Display area
}
int main(int argc, char **argv)
{
printf("hello world\n");
glutInit(&argc, argv);
glutInitDisplayMode
(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(ww,wh);
glutInitWindowPosition(180,90); //position on screen
glutCreateWindow("opengl window");
MyInit();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
함수 정의시 클래스 이름이 누락되었습니다. –
여기에 질문이없는 것 같습니다. – Claies