Trying to get GLUT working on Xcode

I have a Mac Snow Leopard (version 10.6.5) and Xcode installed (version 3.2.4; 64 bit).

I am new to Open GL and am just getting started; trying to create my first app.

Since I do not know objective C, I thought I would start using GLUT.

I am just trying to draw a black window.

Steps I followed:

  1. Created a new project with and selected “Cocoa Application”

  2. In the Linked Framedworks, added OpenGL and GLUT; deleted Cocoa

  3. Created a main.c and pasted the following code
    #include <stdlib.h>

#include <GLUT/glut.h>

void display(void)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glutSwapBuffers();

}

void reshape(int width, int height)
{
glViewport(0, 0, width, height);
}

void idle(void)
{
glutPostRedisplay();
}

int main(int argc, char** argv)
{
glutInit(&argc, argv);

glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(640, 480);

glutCreateWindow("GLUT Program");

glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutIdleFunc(idle);

glutMainLoop();
return EXIT_SUCCESS;

}

  1. Did a build and run but get the following linking error:
    ld: duplicate symbol _main in /Users/NewOglUser/Scratch/OGL/XcodeGLUT/build/XcodeGLUT.build/Debug/XcodeGLUT.build/Objects-normal/x86_64/main-C7DF8B59B4D4D553.o and /Users/cheenu/Scratch/OGL/XcodeGLUT/build/XcodeGLUT.build/Debug/XcodeGLUT.build/Objects-normal/x86_64/main-B9843B6026D6EFA4.o

Any ideas on what I am missing?

Should I be going this route or just go through the pain of learning minimal objective C first?

My aim is to get an understanding of OpenGL (fairly new to 3D) and hence I am trying to write some apps to understand the spec.

Thanks very much for any help and advice on this!

The build error is telling you exactly what’s wrong. You have two main() implementations.

The template includes a few other files implementing the basic Cocoa skeleton, which you should delete if you want a basic C GLUT app:
main.m
<app name>_AppDelegate.*
MainMenu.xib

See also:
http://blog.onesadcookie.com/2007/12/xcodeglut-tutorial.html

That did it. Thanks!

I had gone through the tutorial above which I think is on a different Xcode version than mine.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.