# OpenGL Linker errors in DevC++ (AARGH)

## Recommended Posts

Hey all, Trying to get into GL coding, but keep failing miserably. I am currently following the "OpenGL Programming Guide" book, copying tutorials into DevCpp and trying them out. However, they just don't work. Here is the code I've tried #include <GL/glut.h> void display (void) { glColor3f(1.0, 1.0, 1.0); glBegin(GL_POLYGON); glVertex3f(0.25, 0.25, 0.0); glVertex3f(0.75, 0.25, 0.0); glVertex3f(0.75, 0.75, 0.0); glVertex3f(0.25, 0.75, 0.0); glEnd(); glFlush(); } void init (void) { glClearColor(0.0, 0.0, 0.0, 0.0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); } int main(int argc, char** argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(250,250); glutInitWindowPosition(100,100); glutCreateWindow("Example 1-2: a white square"); init(); glutDisplayFunc(display); glutMainLoop(); return 0; } And I'm linking with: -lopengl32 -lglu32 I get linker errors. Here is my compile log: Compiler: Default compiler Building Makefile: "D:\Programming\RED BOOK EXAMPLES\1-2 white square\Makefile.win" Executing make clean rm -f square.o Project1.exe gcc.exe -c square.c -o square.o -I"D:/Dev-Cpp/include" gcc.exe square.o -o "Project1.exe" -L"D:/Dev-Cpp/lib" -lopengl32 -lglu32 square.o(.text+0x1c):square.c: undefined reference to __glutInitWithExit' square.o(.text+0x37):square.c: undefined reference to __glutCreateWindowWithExit' square.o(.text+0x52):square.c: undefined reference to __glutCreateMenuWithExit' square.o(.text+0x79):square.c: undefined reference to _imp__glColor3f' square.o(.text+0x87):square.c: undefined reference to _imp__glBegin' square.o(.text+0xa8):square.c: undefined reference to _imp__glVertex3f' square.o(.text+0xc9):square.c: undefined reference to _imp__glVertex3f' square.o(.text+0xea):square.c: undefined reference to _imp__glVertex3f' square.o(.text+0x10b):square.c: undefined reference to _imp__glVertex3f' square.o(.text+0x112):square.c: undefined reference to _imp__glEnd' square.o(.text+0x119):square.c: undefined reference to _imp__glFlush' square.o(.text+0x14b):square.c: undefined reference to _imp__glClearColor' square.o(.text+0x159):square.c: undefined reference to _imp__glMatrixMode' square.o(.text+0x160):square.c: undefined reference to _imp__glLoadIdentity' square.o(.text+0x18e):square.c: undefined reference to _imp__glOrtho' square.o(.text+0x1da):square.c: undefined reference to glutInitDisplayMode' square.o(.text+0x1ee):square.c: undefined reference to glutInitWindowSize' square.o(.text+0x202):square.c: undefined reference to glutInitWindowPosition' square.o(.text+0x21f):square.c: undefined reference to glutDisplayFunc' square.o(.text+0x224):square.c: undefined reference to glutMainLoop' collect2: ld returned 1 exit status make.exe: *** [Project1.exe] Error 1 Execution terminated Can someone please help? I'm sure the problem isn't too complicated, I just can't fix it.

##### Share on other sites
glu and glut are 2 different libraries. You need GLUT too. Never used it, so I don't know where you get it.

Also, DevC++ is an old, abandonned IDE. I suggest you download the free MSVC++ 2005 express edition, or you run MinGW under Code::Blocks instead of DevC++.

##### Share on other sites
Sorry about that, have edited my lnker options a few times, forgot glut this time. However, still 21 errors

Compiler: Default compiler
Building Makefile: "D:\Programming\RED BOOK EXAMPLES\1-2 white square\Makefile.win"
Executing make clean
rm -f square.o Project1.exe

gcc.exe -c square.c -o square.o -I"D:/Dev-Cpp/include"

gcc.exe square.o -o "Project1.exe" -L"D:/Dev-Cpp/lib" -lopengl32 -lglu32 -lglut32

square.o(.text+0x1c):square.c: undefined reference to __glutInitWithExit'
square.o(.text+0x37):square.c: undefined reference to __glutCreateWindowWithExit'
square.o(.text+0x52):square.c: undefined reference to __glutCreateMenuWithExit'

square.o(.text+0x79):square.c: undefined reference to _imp__glColor3f'
square.o(.text+0x87):square.c: undefined reference to _imp__glBegin'

square.o(.text+0xa8):square.c: undefined reference to _imp__glVertex3f'
square.o(.text+0xc9):square.c: undefined reference to _imp__glVertex3f'
square.o(.text+0xea):square.c: undefined reference to _imp__glVertex3f'
square.o(.text+0x10b):square.c: undefined reference to _imp__glVertex3f'
square.o(.text+0x112):square.c: undefined reference to _imp__glEnd'
square.o(.text+0x119):square.c: undefined reference to _imp__glFlush'
square.o(.text+0x14b):square.c: undefined reference to _imp__glClearColor'
square.o(.text+0x159):square.c: undefined reference to _imp__glMatrixMode'
square.o(.text+0x18e):square.c: undefined reference to _imp__glOrtho'
square.o(.text+0x1da):square.c: undefined reference to glutInitDisplayMode'

square.o(.text+0x1ee):square.c: undefined reference to glutInitWindowSize'
square.o(.text+0x202):square.c: undefined reference to glutInitWindowPosition'
square.o(.text+0x21f):square.c: undefined reference to glutDisplayFunc'
square.o(.text+0x224):square.c: undefined reference to glutMainLoop'
collect2: ld returned 1 exit status

make.exe: *** [Project1.exe] Error 1

Execution terminated

##### Share on other sites
It seem you have your libraries so the only thing that is not present is the
#include <gl\gl.h> and if glut.h is in the "gl" directory also then you should change it to #include <gl\glut.h>

##### Share on other sites
These are what I use for includes: windows.h, gl\gl.h, gl\glu.h, and gl\glaux.h. My linker looks like this: -lopengl32 -lglu32 -lglaux -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -luuid -lodbc32 -lodbccp32. I never get any linker errors or include errors with this. Don't ask me what all is in the library:P I forgot, but found them in google. BTW, i'm using Dev C++ too.

##### Share on other sites
Click on the project menu and go to project options. Find the box with the heading linker.

-lopengl32
-lglut (or -lglut32 cant remember)

that should do it:)

##### Share on other sites
Dosser,
The easiest way to start OpenGL applications with Dev-C++ is using the project template. When you install Dev-C++, an OpenGL project template comes with it. When you install GLUT package(pak), a GLUT project template is automatically added into Dev-C++.

The project template configures all settings for me, for example, linking required libraries. I only need to replace my source codes into the project. It is very convenient to me to create new OpenGL application right away with Dev-C++.

Try the GLUT project template first and compile the sample code. If there is no error, then, everything is ready to go. If there are errors (link or compile errors) then, you can tell the setting of Dev-C++ is broken.

Here is instructions if you don't know where is glut project template;
File >> New >> Project...
"New project..." window is pop up, then select:
Multimedia tab
you will see glut and OpenGL project template icons.

By the way, the link option for GLUT app should be like this:
-lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32

##### Share on other sites
I'm starting to think there's a problem with my GLUT

I've been trying out the template programs, and can get the standard "openGL" program to work (using windows to open the window, respond to key press etc.). I don't have an option for a glut program, but do have 'freeglut' option. This doesn't link properly. Here are the errors from the default freeglut program.

Compiler: Default compiler
Building Makefile: "D:\Dev-Cpp\Makefile.win"
Executing make...
make.exe -f "D:\Dev-Cpp\Makefile.win" all
gcc.exe -c main9.c -o main9.o -I"D:/Dev-Cpp/include" -DFREEGLUT_STATIC

gcc.exe main9.o -o "Project4.exe" -L"D:/Dev-Cpp/lib" -mwindows -lfreeglut -lglu32 -lopengl32 -lwinmm -lgdi32

Warning: resolving __imp__glViewport by linking to __imp__glViewport@16
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
Warning: resolving __imp__glMatrixMode by linking to __imp__glMatrixMode@4
Warning: resolving __imp__glPushMatrix by linking to __imp__glPushMatrix@0
Warning: resolving __imp__glPopMatrix by linking to __imp__glPopMatrix@0
main9.o(.text+0x1c):main9.c: undefined reference to __glutInitWithExit'
main9.o(.text+0x37):main9.c: undefined reference to __glutCreateWindowWithExit'
main9.o(.text+0x52):main9.c: undefined reference to __glutCreateMenuWithExit'
main9.o(.text+0xdc):main9.c: undefined reference to _imp__glFrustum'
main9.o(.text+0x134):main9.c: undefined reference to _imp__glClear'
main9.o(.text+0x14c):main9.c: undefined reference to _imp__glColor3d'
main9.o(.text+0x177):main9.c: undefined reference to _imp__glTranslated'
main9.o(.text+0x199):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x1b8):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x202):main9.c: undefined reference to _imp__glTranslated'
main9.o(.text+0x224):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x243):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x297):main9.c: undefined reference to _imp__glTranslated'
main9.o(.text+0x2b9):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x2d8):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x334):main9.c: undefined reference to _imp__glTranslated'
main9.o(.text+0x356):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x375):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x3bf):main9.c: undefined reference to _imp__glTranslated'
main9.o(.text+0x3e1):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x400):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x454):main9.c: undefined reference to _imp__glTranslated'
main9.o(.text+0x476):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x495):main9.c: undefined reference to _imp__glRotated'
main9.o(.text+0x624):main9.c: undefined reference to _imp__glClearColor'
main9.o(.text+0x632):main9.c: undefined reference to _imp__glEnable'
main9.o(.text+0x640):main9.c: undefined reference to _imp__glCullFace'
main9.o(.text+0x64e):main9.c: undefined reference to _imp__glEnable'
main9.o(.text+0x65c):main9.c: undefined reference to _imp__glDepthFunc'
main9.o(.text+0x66a):main9.c: undefined reference to _imp__glEnable'
main9.o(.text+0x678):main9.c: undefined reference to _imp__glEnable'
main9.o(.text+0x686):main9.c: undefined reference to _imp__glEnable'
main9.o(.text+0x694):main9.c: undefined reference to _imp__glEnable'

main9.o(.text+0x6b2):main9.c: undefined reference to _imp__glLightfv'
main9.o(.text+0x6d0):main9.c: undefined reference to _imp__glLightfv'

main9.o(.text+0x6ee):main9.c: undefined reference to _imp__glLightfv'
main9.o(.text+0x70c):main9.c: undefined reference to _imp__glLightfv'

main9.o(.text+0x72a):main9.c: undefined reference to _imp__glMaterialfv'
main9.o(.text+0x748):main9.c: undefined reference to _imp__glMaterialfv'
main9.o(.text+0x766):main9.c: undefined reference to _imp__glMaterialfv'
main9.o(.text+0x784):main9.c: undefined reference to _imp__glMaterialfv'
collect2: ld returned 1 exit status

make.exe: *** [Project4.exe] Error 1

Execution terminated

Should I just give up on DevCpp and try again with MSVC, or will I get the same problems there too?

##### Share on other sites
Dosser,
I use glut.3.7.6+.DevPak instead of freeglut.

http://www.nigels.com/glt/devpak/

##### Share on other sites
Hmm, i have the same with issue with Glut. I installed the dev-pak and the default example program does not linker correct.

##### Share on other sites
I just installed the devpak that songho linked to, and it worked fine. The default programs work now, and if I use the 'glut' template (replacing the sample code with my own), my own programs work too.

Thanks :D

##### Share on other sites
Hey that works for me as well..

Thanks to dosser for raising this issue and thanks to songho for the link.

Feels good to have this working.... now off to some coding...

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627752
• Total Posts
2978928
• ### Similar Content

• Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
So, here's what the plan is so far as far as loading goes:
Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!

• I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks

• A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

-What I'm using:
C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.
-Questions
Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.

• 11
• 10
• 10
• 22
• 14