PDA

View Full Version : unreferenced items in glut.h



BertusDries
01-25-2011, 01:09 AM
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

mobeen
01-25-2011, 01:21 AM
Try freeglut http://freeglut.sourceforge.net/. (http://freeglut.sourceforge.net/) I think the glut version u have is old.

BertusDries
01-25-2011, 04:11 AM
I have version 3.6.7

mobeen
01-25-2011, 04:16 AM
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.

BertusDries
01-25-2011, 05:42 AM
In the mean time I have tried freeglut but I get the same results

mobeen
01-25-2011, 06:03 AM
Could u post the minimal freeglut code here and what errors it gives u?

ugluk
01-25-2011, 06:12 AM
Obviously, you don't link with glut, whatever version you have. Try -lglut switch.

BertusDries
01-25-2011, 07:15 AM
This is in glut.h of freeglut 2.1.4
An example of the error is:

614:1 undefined reference to `_imp____glutCreateMenuWithExit@8

BertusDries
01-25-2011, 08:06 AM
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.

marshats
01-25-2011, 08:08 AM
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 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=103685#Post1036 85) which uses #define GLUT_DISABLE_ATEXIT_HACK

mobeen
01-25-2011, 08:10 AM
This is in glut.h of freeglut 2.1.4
An example of the error is:

614:1 undefined reference to `_imp____glutCreateMenuWithExit@8
Could u post the code. I need to see which function/s are u calling that are invoking glutCreateMenuWithExit.

ugluk
01-25-2011, 08:12 AM
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.

BertusDries
01-25-2011, 08:31 AM
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.

BertusDries
01-25-2011, 08:38 AM
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.

marshats
01-25-2011, 09:30 AM
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) &amp;&amp; !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.

BertusDries
01-25-2011, 11:52 PM
It doesn't work

mobeen
01-25-2011, 11:54 PM
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