View Full Version : Basic compile question

Zachary Clifton
02-02-2010, 08:45 PM
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(&amp;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!

Zachary Clifton
02-02-2010, 10:21 PM
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:


02-17-2010, 01:10 AM
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.

02-17-2010, 11:57 PM
Probably in the .cpp (or .mm) file and not the .h, which is what I presume is listed above.

02-18-2010, 03:45 AM
But you never put complete functions in a .h file, least of all the main program.

02-18-2010, 11:06 AM
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?