1

I am using Code::Blocks with a MinGW compiler. These are my includes:

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif

If I try to use a function

glutMainLoopEvent();

It throws an error:

'glutMainLoopEvent' was not declared in this scope.

The function

glutMainLoop();

Works perfectly though.

If I try to include both glut and freeglut (I have correctly installed it, I made sure to watch several videos a few times carefully following the steps) like this:

#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#include <GL/freeglut.h>
#endif

I get 24 of errors such as:

undefined reference to `_imp____glutInitWithExit@12'
undefined reference to `_imp____glutCreateWindowWithExit@8'
undefined reference to `glClearColor@16'

But these don't include the error I was getting before!! From what I can understand, I can include either glut or freeglut, but not both together. How do I figure this out? Thanks!

EDIT:

Linker options:

-lfreeglut
-lopengl32
-lglu32

Completely eliminated the problem, now it works as expected.

DDomjosa
  • 113
  • 6
  • 1
    Possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – BDL Dec 27 '15 at 19:33
  • Why do you want to use both GLUT and freeglut? Mixing two separate implementations of (mostly) the same API sounds like a recipe for failure. – Reto Koradi Dec 27 '15 at 22:24

1 Answers1

0

The later errors about undefined references are linker errors, not compiler errors. You have to link you program (in addition to including the header files) against glut and/or the freeglut library. This is done by adding the following options to the linker:

-lfreeglu
BDL
  • 21,052
  • 22
  • 49
  • 55
  • Please elaborate, I don't know where to start. – DDomjosa Dec 27 '15 at 19:43
  • @DDomjosa, the linker option `-l` followed by a library name tells the linker to look for unresolved symbols in said library. You might read up on the basics of how linkers function before attempting code in C++. – ThomasMcLeod Dec 27 '15 at 21:53
  • @ThomasMcLeod I've been learning C++ for over 3 months and I never had a need to mess with linkers. Admittedly, I was working with simple command line programs. – DDomjosa Dec 27 '15 at 22:54