OpenGL libraries not working?

I’ve been trying to follow some of the tutorial for OpenGL but I always get to the very end and try to compile it and get a list of undefined references, even though I have the libraries that the tutorials say to include. I’m using Dev-C++, is there anything extra that I need to download for everything to work right? or am I just doing something wrong?

Is it a compiler error or link error?

Usually if it’s a compiler error you’ll see errors like “use of undefined symbol ‘foo’”, which generally indicates that you’ve screwed up somewhere syntactically. With link errors, you’ll see things like "unresolved external symbol ‘foo’, and they are due to not linking with the appropriate library (opengl32.lib, for example).

I don’t know about DevC++, but in VC++ you can

#include <windows.h>
#include <GL/gl.h>
#pragma comment(lib,“opengl32.lib”)

for compile-time binding, or use LoadLibrary/GetProcAddress for dynamic binding (I seriously doubt you need/want to fool with that).

I bet you can add a command line switch in your IDE’s project options dialog as well. Look for an linker option entry like “Additional dependencies” or something like that.

it’s linker errors, it says, undefined reference to… but I have:

#pragma comment(lib, “opengl32.lib”)
#pragma comment(lib, “glu32.lib”)
#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <stdio.h>

all of those at the top, and I’ve even tryed copying the completed code they give at the end of the tutorial and it still doesn’t work, as for the other stuff you said at the end…I have no idea what you were talking about

Humph! Well I’m mystified.

Can you post the compiler error log so we can see the error messages exactly as they’re displayed in DevC?

If they are indeed link errors, and they mention OpenGL/GLU functions by name, then your IDE can’t find the opengl32.lib/glu32.lib library for some reason or another. Check your DevC installation folders and verify that those libraries exist. Check that DevC has been installed properly and has the proper environment variables and/or path configuration. I’d hate to suggest a reinstall, but that could be a last resort if all else fails. AFAIK, DevC installs with everything needed for OpenGL…

It’s hard for me to say with certainty since I’ve never used DevC before. Perhaps someone with some DevC experience would be so kind as to chime in :slight_smile:

It looks like MinGW is included with DevC++, and that installs Windows headers and import libraries.

I also see a place to grab “devpacks”, and 3D graphics/OpenGL is among them.

These look to be helpful sites:

Here is a demo project that uses DevC++:

And I think NeHe has some DevC++ projects too.

I would at least make sure you have the latest version of DevC++ installed, with all the relevant devpacks/packages. Then load one of the Dev-C++ OpenGL demo projects into the IDE and build it. Don’t copy the code, load the project. This way you can be sure the project settings are what they should be.

Wish I had a silver bullet for you :slight_smile:

here’s the compile log:
Compiler: Default compiler
Building Makefile: “C:\Dev-Cpp\GlUtil\”
Executing make…
make.exe -f “C:\Dev-Cpp\GlUtil\” all
g++.exe -c GLUtil.cpp -o GLUtil.o -I"C:/Dev-Cpp/include/c++" -I"C:/Dev-Cpp/include/c++/mingw32" -I"C:/Dev-Cpp/include/c++/backward" -I"C:/Dev-Cpp/include"

g++.exe GLUtil.o main.o -o “GlUtil.exe” -L"C:/Dev-Cpp/lib"

GLUtil.o(.text+0x469):GLUtil.cpp: undefined reference to `ChoosePixelFormat@8’

GLUtil.o(.text+0x4be):GLUtil.cpp: undefined reference to SetPixelFormat@12' GLUtil.o(.text+0x503):GLUtil.cpp: undefined reference towglCreateContext@4’
GLUtil.o(.text+0x558):GLUtil.cpp: undefined reference to wglMakeCurrent@8' GLUtil.o(.text+0x796):GLUtil.cpp: undefined reference towglMakeCurrent@8’
GLUtil.o(.text+0x7be):GLUtil.cpp: undefined reference to wglDeleteContext@4' GLUtil.o(.text+0xb8f):GLUtil.cpp: undefined reference toSwapBuffers@4’

main.o(.text+0xf):main.cpp: undefined reference to glClearColor@16' main.o(.text+0x29):main.cpp: undefined reference toglClear@4’
main.o(.text+0x31):main.cpp: undefined reference to glFlush@0' main.o(.text$_ZN6OpenGL6createEv+0x36):main.cpp: undefined reference toOpenGL::instance’

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

Execution terminated

I think my version of Dev is probably an old one so I’ll try getting the new version for now

That sounds like a good plan, grab the latest version. There is not much else I can do for you at this point, short of downloading and installing DevC myself, which I’d do if I had time right now, but I don’t :slight_smile: I’m sure this is something simple though, and will hopefully be cleared up with a fresh install and a load of a good demo project. Please keep us posted :slight_smile:

ok, i downloaded the new version and it didn’t help…I think it may have given me some extras too…I’ll try some of the other things you mentioned

ok, I think I got it, I had to go into the project options and add some libraries in there, but there’s still a couple more errors, thanks for all your help

those must have been errors with the program because i ran another program that didn’t work before and it works fine now, again, thanks full your help

those errors must have been a problem with that program because i tried another one that didn’t work before and it works fine now, again, thanks for all your help, I appreciate it

That’s good news. Glad to help.

Man I hate it when my system stone-walls me like that :slight_smile: