PDA

View Full Version : OpenGL libraries not working?



Evilcatt09
11-20-2005, 09:36 AM
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?

11-20-2005, 11:55 AM
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.

Evilcatt09
11-20-2005, 01:32 PM
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

11-20-2005, 01:50 PM
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 :)

11-20-2005, 07:53 PM
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:
http://www.bloodshed.net/dev/devcpp.html
http://www.bloodshed.net/faq.html
http://devpaks.org/

Here is a demo project that uses DevC++:
http://www.codeproject.com/opengl/openglstruct.asp

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 :)

Evilcatt09
11-21-2005, 01:48 PM
here's the compile log:
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\GlUtil\Makefile.win"
Executing make...
make.exe -f "C:\Dev-Cpp\GlUtil\Makefile.win" 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 to `wglCreateContext@4'
GLUtil.o(.text+0x558):GLUtil.cpp: undefined reference to `wglMakeCurrent@8'
GLUtil.o(.text+0x796):GLUtil.cpp: undefined reference to `wglMakeCurrent@8'
GLUtil.o(.text+0x7be):GLUtil.cpp: undefined reference to `wglDeleteContext@4'
GLUtil.o(.text+0xb8f):GLUtil.cpp: undefined reference to `SwapBuffers@4'

main.o(.text+0xf):main.cpp: undefined reference to `glClearColor@16'
main.o(.text+0x29):main.cpp: undefined reference to `glClear@4'
main.o(.text+0x31):main.cpp: undefined reference to `glFlush@0'
main.o(.text$_ZN6OpenGL6createEv+0x36):main.cpp: undefined reference to `OpenGL::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

11-21-2005, 02:02 PM
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 :) 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 :)

Evilcatt09
11-21-2005, 02:20 PM
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

Evilcatt09
11-21-2005, 02:40 PM
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

Evilcatt09
11-21-2005, 02:46 PM
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

Evilcatt09
11-21-2005, 02:47 PM
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

11-21-2005, 02:51 PM
That's good news. Glad to help.

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