PDA

View Full Version : Beginning program producing excessive errors



00Wolf
04-10-2009, 05:50 PM
I am trying to compile NeHe's OpenGL lesson 1, but it won't compile. I am running on a Windows platform, using Code::Blocks and MinGW. My MinGW install has: libglu32.a, libglut32.a, libglaux.a, libglut.a, gl.h, glaux.h, glext.h, glu.h, glut.h, glext.h, and wglext.h. Also, if anyone knows where I can find updated versions of everything except GLut, it would be greatly apperciated.

Riskz
04-10-2009, 06:47 PM
What errors are you getting?
compiler errors or runtime errors? (EDIT: sorry you say it isn't compiling)
A little more info would help to find the problem

Regards

00Wolf
04-10-2009, 07:36 PM
Sorry. I get linker errors, the GL functions don't exist.

draftomatic
04-11-2009, 01:37 PM
You should post (copy/paste) the exact errors you are getting.

00Wolf
04-11-2009, 01:41 PM
Here you go:

Compiling: C:\Users\Sly\Desktop\Lesson1.cpp
Linking console executable: C:\Users\Sly\Desktop\Lesson1.exe
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x31): undefined reference to `glViewport@16'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x40): undefined reference to `glMatrixMode@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x48): undefined reference to `glLoadIdentity@0'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x76): undefined reference to `gluPerspective@32'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x85): undefined reference to `glMatrixMode@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x8d): undefined reference to `glLoadIdentity@0'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xa2): undefined reference to `glShadeModel@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xcd): undefined reference to `glClearColor@16'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xda): undefined reference to `glClearDepth@8'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xe9): undefined reference to `glEnable@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xf8): undefined reference to `glDepthFunc@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x10f): undefined reference to `glHint@8'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x12c): undefined reference to `glClear@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x134): undefined reference to `glLoadIdentity@0'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x192): undefined reference to `wglMakeCurrent@8'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x1cd): undefined reference to `wglDeleteContext@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x672): undefined reference to `ChoosePixelFormat@8'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x6d6): undefined reference to `SetPixelFormat@12'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x725): undefined reference to `wglCreateContext@4'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x787): undefined reference to `wglMakeCurrent@8'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xabd): undefined reference to `SwapBuffers@4'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 4 seconds)
21 errors, 0 warnings

Riskz
04-11-2009, 05:09 PM
Could you post the arguments which you are passing to the linker and your include directives?

00Wolf
04-11-2009, 09:09 PM
I am just compiling NeHe's OpenGL lesson 1. If you want to see that stuff, look there.

Stuart McDonald
04-11-2009, 11:45 PM
Are you linking opengl32?

00Wolf
04-12-2009, 09:00 AM
I don't know what you mean.

Stuart McDonald
04-12-2009, 01:56 PM
I don't know what you mean.
Yes, my answer is the equivalent of your question. Not really enough information to help. Always try and provide people with as much as you can. You say you are just using the NeHe tutorials, but 100s of people have got them to work, so that's not much help

Anyway, from your answer I assume you don't understand how a program is compiled and linked to produce an executable. So here's the (simplified) basics...Compiling looks at the syntax and checks everything is ok. Linking takes all the parts and "links" them to produce the final program. It's at that point that all the different bits of code your program uses need to be found. For example the code for GLUT is found libglut.

The OpenGL functions (that your code and GLUT and GLU etc) all use are in the opengl32 library. Since you are getting those errors I assume that you are not linking in that library. I use Eclipse, Cygwin and Makefiles so my compile line is something like

g++ -D WIN32 -mno-cyywin myCode.C -l glut32 -l glu32 -l opengl32The order is important since glut and glu uses opengl so it need to be last.

You need to get opengl32 into your list of libraries for your program. You may also need to tell it where to find the library e.g. MinGW/lib/libopengl32.a. I don't use Code::blocks so can't help there.

00Wolf
04-12-2009, 06:00 PM
I knew most of that, except the -l command in gcc, but how would you specify what to link against in Code::Blocks?

00Wolf
04-12-2009, 06:07 PM
Never mind. I got it. But after linking against every library I have, I still get this.

C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x672): undefined reference to `ChoosePixelFormat@8'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0x6d6): undefined reference to `SetPixelFormat@12'
C:\Users\Sly\Desktop\Lesson1.o:Lesson1.cpp:(.text+ 0xabd): undefined reference to `SwapBuffers@4'
collect2: ld returned 1 exit status
Process terminated with status 1 (0 minutes, 1 seconds)
3 errors, 0 warnings

Stuart McDonald
04-12-2009, 10:40 PM
Well I don't use windows, but a quick Google for these shows that these need Gdi32.lib. Does that help?

00Wolf
04-13-2009, 06:51 AM
Thanks a lot. It was included in MinGW, but I didn't know to link against it. I am switching to Linux soon, anyway. Any recommendations?

Stuart McDonald
04-13-2009, 01:07 PM
When I say I don't use Windows I mean I don't use any of it's libraries. I currently still run a Windoze machine, but use cygwin to make it easier to port to Linux. Similary I use GLFW for my keyboard, mouse and window creation and OpenAL for sound since these are cross-platform. There are more functional libraries out there, but I like to use as simple and low-level as possible (whilst still being cross-platform).

My build environment is Eclipse, but that's purely because I'm used to it for Java, and autoconf (which I wouldn't recommend!). Code::Blocks is (I believe) much better for C++, but Eclipse will catch up eventually.

00Wolf
04-13-2009, 08:53 PM
I tried Eclipse, but I didn't like it for C, not C++ development. I was looking for an alternative to Dev-C++, but I found Eclipse to be a little too much like Visual Studio, too hard to use. But the question still stands, know of any good Linux flavors?

Ilian Dinev
04-13-2009, 09:33 PM
Last time I checked thoroughly, about a year ago, all IDEs for C++ on Linux were a joke. Except for one commercial package, that had half the features of VS6 at triple the price of the whole VS2k8pro package.
Meanwhile, VS2k8 Express gives everything necessary for indie devs for no cost and no registration either. Code and build the stuff on "Winboze", have crosscompilers/makefiles/build-tools ready and VirtualBox running. You'll anyway have to write the code on one OS - why not do it on the developer-friendly one.

Or go guerrila-style and use Vim...

Edit: Stuart's post confused me a bit that your intent is to code in a platform-independent way. If you'll be making only linux elfs, Eclipse is easily the best - even if it's slow and lacking in features. But do spend 5 minutes in learning the command-line args to gcc, you will learn how to make a three-line bash script to build and run your app; and prove extremely useful in any case.

Rosario Leonardi
04-14-2009, 12:57 AM
Try Qt-Creator. :)
Multiplatform and easy to use.

00Wolf
04-15-2009, 07:44 AM
Thanks.