0

I'm trying to compile an old OpenGL project using MinGW on Windows, but I'm running into linker errors for every OpenGL/GLUT function. My setup:

main.cpp includes:

#include <time.h>
#include <iostream>
#include <math.h>
#include <windows.h>
#include "glut.h"

In the same directory as main.cpp, I have:

  • open32.dll
  • glu32.dll
  • glut32.dll (downloaded)
  • glut.lib (downloaded)
  • glut.h (downloaded)
  • glut.def (not sure if needed)

In MinGW\include\GL I have:

  • gl.h
  • glu.h
  • glext.h (These came with the MingGW installation)

Build command:

path %path%;C:\MinGW\bin
g++ -o program.exe main.cpp glut32.lib

Error example:

undefined reference to `glClearColor@16`

...and similar errors for all OpenGL and GLUT functions.

How do I correctly link OpenGL and GLUT with MinGW to resolve these undefined references? What libraries do I need to link, and in what order?

2 Answers 2

3

You don't link with the actual OpenGL library, you need to add -lGL to your command:

$ g++ -o program.exe main.cpp glut32.lib -lGL
Sign up to request clarification or add additional context in comments.

5 Comments

c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot find -lGL but wait, i dont want to link item from "global repository", i want to have everything in project folder. then in near feature i will not have such problems
the idea is to not keep everything in your project directory: then in the future, when you have multiple projects, you won't have to manually update all of them if you want to get a new OpenGL version
but when i want to use different version of OpenGL. but also when i link dll from system32 it also dont working
On Windows the library is called opengl32.dll, so it's -lopengl32 not -lGL.
I try to compile this with g++ -o program.exe main.cpp glut32.lib -L. -lglu32 -lglut32 -lopengl32 this library glu32.dll, glut32.dll and opengl32.dll i have in folder with source. but then i get error ./glu32.dll: file not recognized: File format not recognized
-2

You might want to keep your dll files in SysWOW64 folder instead of System32 folder in case you have x64 libraries.

1 Comment

On 64-bit Windows, System32 holds 64-bit DLLs, while SysWOW64 holds 32-bit DLLs.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.