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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With