I just wrote a very simple opengl app using C++ and glut. But when it compiles it gives me some linking errors. Here is the code:

#include <windows.h>
#include <gl\glut.h>

void init(void);
void display(void);

int main(int argc, char** argv)
glutInit (&argc, argv) ;
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB) ;
glutInitWindowSize (400, 100) ;
glutInitWindowPosition (100, 100) ;
glutCreateWindow (“First Chapter - Opening an OpenGL Window”) ;

init() ;
glutDisplayFunc (display) ;
glutMainLoop () ;
return 0 ;

void init(void)
glClearColor(1.0, 1.0, 1.0, 0.0) ;
glShadeModel(GL_FLAT) ;

void display(void)
glutSwapBuffers() ;

That code is just from a tutorial I followed on opening a window using glut. The error I get when compiling is this:

link gltest,user32+kernel32/noi;
OPTLINK ® for Win32 Release 7.50B1
Copyright © Digital Mars 1989 - 2001 All Rights Reserved

Warning 2: File Not Found winmm.lib
Error 43: Not a Valid Library File

— errorlevel 1

I know that I need this winmm.lib, but I cannot find it anywhere at all, so I figure I’m just doing something wrong. What is going on? What do I need to do to fix this?

BTW, I’m using that free digital mars compiler, could that be part of the problem?

U have to include winmm.lib at your linking project.
1)click project
2)select setting
3)select link
4)type winmm.lib in the object/library module.
That;s it.

U have to include winmm.lib at your linking project.
1)click project
2)select setting
3)select link
4)type winmm.lib in the object/library module.
That;s it.

Ummm, no, that’s not it. I’m not familiar with this particular compiler, but the error message indicates that he does not have winmm.lib and that opengl32.lib is not the right one. Did you get this opengl32.lib with your compiler or somewhere else? You do realize that most compilers can’t read the library files of other compilers, don’t you? Try to get the correct libraries. If you can’t find them, get another compiler. Try downloading Dev-C++ from:

Thanks for telling me about that compiler aaron, I was looking for something like that. But now, when I compile (same code) I get:

Building Makefile: “C:\Dev-Cpp\gluttest\”
Executing make…
make.exe -f “C:\Dev-Cpp\gluttest\” all
g++.exe gluttest.o -o “gluttest.exe” -L"C:/Dev-Cpp/lib" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/g+±3" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/gl" -s

gluttest.o(.text+0x17):gluttest.cpp: undefined reference to __glutInitWithExit@12' gluttest.o(.text+0x37):gluttest.cpp: undefined reference to__glutCreateWindowWithExit@8’
gluttest.o(.text+0x5b):gluttest.cpp: undefined reference to __glutCreateMenuWithExit@8' gluttest.o(.text+0xd0):gluttest.cpp: undefined reference toglutInitDisplayMode@4’

gluttest.o(.text+0xe2):gluttest.cpp: undefined reference to glutInitWindowSize@8' gluttest.o(.text+0xf1):gluttest.cpp: undefined reference toglutInitWindowPosition@8’
gluttest.o(.text+0x116):gluttest.cpp: undefined reference to glutDisplayFunc@4' gluttest.o(.text+0x11e):gluttest.cpp: undefined reference toglutMainLoop@0’
gluttest.o(.text+0x148):gluttest.cpp: undefined reference to glClearColor@16' gluttest.o(.text+0x155):gluttest.cpp: undefined reference toglShadeModel@4’
gluttest.o(.text+0x16f):gluttest.cpp: undefined reference to glClear@4' gluttest.o(.text+0x177):gluttest.cpp: undefined reference toglutSwapBuffers@0’

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

Execution terminated

I found the libwinmm.a which I assume is the winmm.lib for devc++. But when I add libwinmm.a into “Linker Options/Optional libs or object files” under Project Options it says it cannot find it. Then when I put in the entire path to the libwinmm.a file, I guess it finds it, but it gives me the original error again.

hm, i don’t see any undefined references depending on winmm.lib.
for those listed, include opengl32.lib and glu32.lib.

(btw, i don’t know any compiler having libraries not ending with *.lib … so i guess your libwinmm.a file ‘was’ just the sourcecode for your compiler to build winmm.lib)

Libraries for GCC (The GNU Compiler Collection) are named lib<name>.a. The “.a” stands for “archive”. You include them with the command -l<name>. Dev-C++ is just an IDE for the Windows port of GCC (and a very good one at that). I don’t see any libraries in the line that links your code:

“g++.exe gluttest.o -o “gluttest.exe” -L"C:/Dev-Cpp/lib” -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/g+±3" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/gl" -s
To include libraries in your project, go to the Project menu, then Project Options. In the line that says “Linker Options/Optional Libs or Object Files” enter -lopengl32 and -lglut32 and any other libraries that you decide you need.

Thank you very much aaron, that worked.