Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode project cannot recognize certain GLUT commands

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?

like image 881
Chris Avatar asked Nov 15 '11 21:11

Chris


2 Answers

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.
like image 190
Keugyeol Avatar answered Sep 23 '22 13:09

Keugyeol


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.

like image 35
101010 Avatar answered Sep 25 '22 13:09

101010