# RED BOOK compile error?

## Recommended Posts

Im looking for some help, I purchased the red book and am trying to compile the first example. and I get the following error. Can someone tell me where im going wrong
E:\c++\OPENGL RED BOOK\chapter_1\simple\src>g++ main.cpp
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x14e): undefined r
eference to glEnable@4'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x186): undefined r
eference to glClear@4'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x18e): undefined r
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x1cc): undefined r
eference to gluLookAt@72'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x1db): undefined r
eference to glBegin@4'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x206): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x228): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x253): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x275): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x2a0): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x2c2): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x2ca): undefined r
eference to glEnd@0'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x2d6): undefined r
eference to glBegin@4'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x301): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x323): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x34e): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x370): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x39b): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x3bd): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x3e8): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x40a): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x435): undefined r
eference to glColor4f@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x457): undefined r
eference to glVertex3f@12'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x45f): undefined r
eference to glEnd@0'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x497): undefined r
eference to glViewport@16'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x4a6): undefined r
eference to glMatrixMode@4'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x4ae): undefined r
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x4d8): undefined r
eference to gluPerspective@32'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x4e7): undefined r
eference to glMatrixMode@4'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x4ef): undefined r
eference to glLoadIdentity@0'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x557): undefined r
eference to SDL_Init'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x5ac): undefined r
eference to SDL_GL_SetAttribute'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x5c0): undefined r
eference to SDL_GL_SetAttribute'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x5d4): undefined r
eference to SDL_GL_SetAttribute'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x5e8): undefined r
eference to SDL_GL_SetAttribute'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x5fc): undefined r
eference to SDL_GL_SetAttribute'
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x610): more undefi
ned references to SDL_GL_SetAttribute' follow
C:\Users\Owner\AppData\Local\Temp/ccGs9VMa.o:main.cpp:(.text+0x6bf): undefinecol
lect2: ld returned 1 exit status`

##### Share on other sites
You're not linking the libraries for the mentioned functions. Make sure you link the libraries for OpenGL and SDL.

##### Share on other sites
OK Ive linked some librarys with the following code.

g++ -lglu32 -lopengl32 -lSDL main.cpp

and now I get the following error

collect2: ld returned 1 exit status

##### Share on other sites
That can't be the only output from ld, what's the complete error message? In fact, what's the entire output that you get when you execute your command. My guess is that you're also getting a "can't find library" message...

##### Share on other sites
It is the complete error message
the following is what i get

E:\c++\OPENGL RED BOOK\chapter_1\simple\src>g++ -lglu32 -lopengl32 -lSDL main.cpp
collect2: ld returned 1 exit status

E:\c++\OPENGL RED BOOK\chapter_1\simple\src>

Im thinking maybe i have one of those computers that has become self aware, and out of protest has decided it will not compile until it gets better pay and conditions. :)

[Edited by - chickencoop on November 11, 2009 11:10:25 PM]

##### Share on other sites
Do you have the libraries you're trying to link in?

Does your compiler know where they are?

##### Share on other sites
Ok I got it working I can now compile chapter 1, It was a linking problem For those who are interested.

i compiled chapter 1 with the following command

g++ -o program.exe main.cpp -lmingw32 -lSDLmain -lSDL -lopengl32 -lglu32

Now I have another question.

I tried compling chapter 2 with the same command and again I get the same error.

so my question now is what libraries do people link in for chapter 2 of the red book?

##### Share on other sites
Hard to guess without seeing the code and/or the book (since you bought it I assume you are not using the 1.1 version). Does it use any functions that start in glut* or wgl* or some other stuff besides standard OpenGL and GLU?

##### Share on other sites
Glut no
Wgl yes.
From searching through the code in the example, calls X11

Its the 2nd edition of the red book

[Edited by - chickencoop on November 18, 2009 1:09:23 AM]

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978700

• 21
• 14
• 12
• 10
• 12