unreferenced items in glut.h

I’m new to OpenGL. I am trying to run a program running on a UBUNTU operating system on my Windows 7 system. In the mean time I have solved a lot of problems with that partly because I want to keep my system neat which means that I want to have programs on a special position (on the D: partition).
I am using the GNAT Programming Studio. When I build the program I get about sixty errors all in the form of:

undefined reference to `__glutCreateMenuWithExit
This one and two others even in glut.h (which are twice mentioned in the list of errors. The others are in a file which #includes only glut.h How can I solve this

Try freeglut http://freeglut.sourceforge.net/. I think the glut version u have is old.

I have version 3.6.7

glut version 3.7.6 was released in Nov 2001.

Get freeglut its much more recent and has code for setting up OpenGL3.0 and above.

In the mean time I have tried freeglut but I get the same results

Could u post the minimal freeglut code here and what errors it gives u?

Obviously, you don’t link with glut, whatever version you have. Try -lglut switch.

This is in glut.h of freeglut 2.1.4
An example of the error is:

614:1 undefined reference to `_imp____glutCreateMenuWithExit@8

I have already tried the -lglut32 switch but that didn’t wotk either, neither did the -L switch. Both switches are linker options and as far as I can see the problem is somewhere in de compiler within GPS.

The error is not related to the header at all whether it is from glut or freeglut. You are not telling your linker to use the libglut.* in GNAT correctly. Not being familar with GNAT IDE, a simple test is to go to the command line and do what was suggested earlier (specify -lglut) ie


gcc main.c -lglut

assuming your simple glut program is called main.c this should tell the linker to link to the glut library and produce a.out. This is what GNAT will do behind the scenes anyway.

Follow up – are you in linux or windows/mingw? On linux use -lglut but on windows/mingw use “-lglut32 -lglu32 -lopengl32 -lwinmm -lgdi32”

also take a look at the suggestion at Post103685 which uses #define GLUT_DISABLE_ATEXIT_HACK

Could u post the code. I need to see which function/s are u calling that are invoking glutCreateMenuWithExit.

Yeah, try to compile from the command line, why trust the GNAT studio, if you can do the real thing by hand. The other thing might be, that the headers are installed but not the libraries.

Try the gentoo distro, much better for development.

I is just the Glut.h or the freeglut.h that does not see the mentioned function I thought I had posted that. on line 614 it is mentioned.

I have no experience with command line invoking the compiler. And in other cases I just have a goodworking system with the GNAT system. I therfore think that it has sopmething todo with the location of some files. The phase in which the problem occurs is with the builder as the messages are presented under the header Builder Results.

What happens if you put the following define above your glut.h include ie code should now look like


#define GLUT_DISABLE_ATEXIT_HACK
include <glut.h>

A little history of the reason to try GLUT_DISABLE_ATEXIT_HACK comes from reading the glut changelog

Work around Microsoft’s bug where atexit callbacks are not
called if exit is called from within a DLL. I had to add new
routines glutCreateWindowWITHEXIT, glutCreateMenuWITHEXIT,
and glutInitWITHEXIT that pass in the exit routine’s function
pointer so GLUT can call this routine and exit with the
atexit callbacks called correctly.

and looking at glut.h on my system shows what GLUT_DISABLE_ATEXIT_HACK affects your function of interest


#if defined(_MSC_VER) && !defined(GLUT_DISABLE_ATEXIT_HACK)
GLUTAPI int GLUTAPIENTRY __glutCreateMenuWithExit(void (GLUTCALLBACK *func)(int), void (__cdecl *exitfunc)(int));
#ifndef GLUT_BUILDING_LIB
static int GLUTAPIENTRY glutCreateMenu_ATEXIT_HACK(void (GLUTCALLBACK *func)(int)) { return __glutCreateMenuWithExit(func, exit); }
#define glutCreateMenu glutCreateMenu_ATEXIT_HACK
#endif
#endif

So it seems to be a windows+glut specific issue that might be fixed by disabling it. This suggests why it works when complied on linux but fails when compiled on windows. Again as has been asked a couple of times – please post a simple code that fails to compile.

It doesn’t work

could u add this preprocessor

#define GLUT_BUILDING_LIB

at the start of your code.
And i repeat the third time could u plz post ur problematic code

Most probably it was happening because Linux doesn’t have ‘windows.h’ header file. I am new to OpenGL but stumbled upon this problem.