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