Basic compile question

I am receiving the following error:

Undefined symbols:
“DrawGLScene()”, referenced from:
__Z11DrawGLScenev$non_lazy_ptr in cc4pHIdQ.o
“InitGL()”, referenced from:
_main in cc4pHIdQ.o
“ReSizeGLScene(int, int)”, referenced from:
__Z13ReSizeGLSceneii$non_lazy_ptr in cc4pHIdQ.o
ld: symbol(s) not found
collect2: ld returned 1 exit status

when trying to compile the following code

#include <OpenGL/gl.h> // Header File For The OpenGL32 Library
#include <OpenGL/glu.h> // Header File For The GLu32 Library
#include <GLUT/glut.h> // Header File For The GLut Library

#define kWindowWidth 400
#define kWindowHeight 300

GLvoid InitGL(GLvoid);
GLvoid DrawGLScene(GLvoid);
GLvoid ReSizeGLScene(int Width, int Height);

int main(int argc, char** argv)
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (kWindowWidth, kWindowHeight);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);




return 0;

Using the following command:

g++ opengltest.cpp -o test -framework OpenGL -framework GLUT

I can’t find any flags that I am missing. Any help is appreciated. Thanks!

I actually just figured out how to get it to compile. The error was definitely stating that the GLvoid functions were not declared. I, however, thought they would have been brought over with the .h files. I did find ported implementations that I copied and pasted into the code here:

But where is the code to the functions InitGL, DrawGLScene and ReSizeGLScene? You have declared them, thereby promising that they exist, but they don’t.

Probably in the .cpp (or .mm) file and not the .h, which is what I presume is listed above.

But you never put complete functions in a .h file, least of all the main program.

Of course you can. It may not be “best” coding practice, but it is often done.

I presume the OP just put what he thought was relevant from both files, or was experimenting.

I’m not sure where you are going with this… Do you have a specific question?

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