I'm trying to build a lighting model program in Xcode but it keeps saying build failed due to undefined symbols, but I don't understand how to fix it. My code is below.
#include <GLUT/glut.h>
#include <stdlib.h>
static GLfloat shift = 0.0; // Initialize the fourth parameter of the plane equation
void init(void)
{
glClearColor (0.0, 0.5, 0.0, 0.0);
glEnable (GL_LIGHTING);
glEnable (GL_LIGHT0);
glEnable (GL_DEPTH_TEST);
}
void display (void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
GLdouble eqn0[4] = {1.0, 0.0, 0.0, shift}; // Parameters array of the first plane
glClipPlane (GL_CLIP_PLANE0, eqn0); // Create the first plane with eqn0 array
// glEnable (GL_CLIP_PLANE0); // Activate the first plane
/* Draw five different objects at different locations */
glLineWidth(2.0);
glPushMatrix();
glutSolidTeapot (2.0);
glTranslatef (3.0, 3.0, 0.0);
glutSolidTorus (0.4, 0.8, 20, 20);
glTranslatef (-6.0, 0.0, 0.0);
glutWireIcosahedron ();
glTranslatef (0.0, -6.0, 0.0);
glutSolidSphere (1.0, 20, 20);
glTranslatef (6.0, 0.0, 0.0);
glutWireCube (2.0);
glPopMatrix();
glutSwapBuffers ();
}
void reshape(int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (60.0, (GLfloat) w/(GLfloat) h, 1.0, 20.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
gluLookAt (0.0,0.0,10.0, 0.0,0.0,0.0, 0.0,1.0,0.0);
}
/* Implement any keyboard function to increase or decrese the value of
"shift" to interactively adjust the position of the clipping plane */
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 'f':
// shift =
glutPostRedisplay ();
break;
case 27:
exit(0);
break;
default:
break;
}
}
int main(int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (800, 800);
glutInitWindowPosition (100, 100);
glutCreateWindow ("Planner clipping");
init ();
glutDisplayFunc (display);
glutReshapeFunc (reshape);
glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}
I need a screen to pop up with a green background and a gray teapot.
Below are the errors that keep occurring:
Showing Recent Issues
Build target lightPA2 of project lightPA2 with configuration Debug
Undefined symbols for architecture x86_64:
"_glClear", referenced from:
display() in main.o
"_glClearColor", referenced from:
init() in main.o
"_glClipPlane", referenced from:
display() in main.o
"_glEnable", referenced from:
init() in main.o
"_glLineWidth", referenced from:
display() in main.o
"_glLoadIdentity", referenced from:
reshape(int, int) in main.o
"_glMatrixMode", referenced from:
reshape(int, int) in main.o
"_glPopMatrix", referenced from:
display() in main.o
"_glPushMatrix", referenced from:
display() in main.o
"_glTranslatef", referenced from:
display() in main.o
"_glViewport", referenced from:
reshape(int, int) in main.o
"_gluLookAt", referenced from:
reshape(int, int) in main.o
"_gluPerspective", referenced from:
reshape(int, int) in main.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)