7
votes

I'm creating a GLUT/OpenGL project in XCode 4. I've added the glut/opengl frameworks, linked all my libraries together-all is good, except for some reason my main() function won't accept glutInit(&argc, argv) and gives me the error message that "there's no matching function call to glutInit(). The strange thing though is that it accepts some of the other glut functions like glutInitDisplayMode() and glutCreateWindow() but just not glutInit().

Also, I'm using 3 callback functions

glutDisplayFunc(DisplayCallback)    
glutReshapeFunc(ReshapeCallback)    
glutKeyboardFunc(KeyboardCallback) 

My project accepts only the first one, but does not recognize the other two, giving the same error as it does with glutInit().

Any ideas as to what could be going wrong?

3
Post a complete, minimal program that demonstrates the problem. - genpfault

3 Answers

37
votes

I've had exactly the same error.

I have finally solved the problem by making changes to the argument of the main() function.

See if the argv is declared as const. Removing it from the main function argument made glutInit error disappear.

// delete const from argv declaration 
int main(int argc, const char * argv[]) // from this,
int main(int argc, char * argv[])       // to this.
2
votes

According to my humble opinion, it's better to const_cast input arguments to avoid type mismatch in C++, take a look at the code snippet below:

glutInit(&argc, const_cast<char**>(argv));

This way you signify to the future reader of your program that you know that argv is a constant and by const_cast-ing it you know what you are doing.

1
votes

Dunno if you found your answer, but it sounds like you haven't added the GLUT framework to your Xcode project (assuming Xcode 4.x):

Click on the top-most project icon in the main window's side bar.

Click the '+' under 'Link Binary With Libraries' and search for 'glut'.

Add that framework.

Make sure

#import <GLUT/glut.h>

Is in your header file.