Beginning program producing excessive errors

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.

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


Sorry. I get linker errors, the GL functions don’t exist.

You should post (copy/paste) the exact errors you are getting.

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 toglMatrixMode@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 togluPerspective@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 toglLoadIdentity@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 toglClearColor@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 toglEnable@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 toglHint@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 toglLoadIdentity@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 towglDeleteContext@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 toSetPixelFormat@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 towglMakeCurrent@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

Could you post the arguments which you are passing to the linker and your include directives?

I am just compiling NeHe’s OpenGL lesson 1. If you want to see that stuff, look there.

Are you linking opengl32?

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 opengl32

The 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.

I knew most of that, except the -l command in gcc, but how would you specify what to link against in Code::Blocks?

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 toSetPixelFormat@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

Well I don’t use windows, but a quick Google for these shows that these need Gdi32.lib. Does that help?

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?

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.

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?

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.

Try Qt-Creator. :slight_smile:
Multiplatform and easy to use.