OpenGL unreferenced function

Hopefully someone can help with this problem.

I use Codeblocks IDE + MingW compiler and try to write an OpenGL program from the book "OpenGL super bible 4th" chapter 1
The error I get when I compile:

obj\Debug\main.o||In function `Z11RenderScenev':|
D:\Codeblock C files\Test_OpenGL\main.cpp|102|undefined reference to `glutWireCube'| -- removed remaining lines, too many lines for forum

||=== Build finished: 24 errors, 0 warnings (0 minutes, 2 seconds) ===|

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

#include "GL/gltools.h"
#include "GL/math3d.h"
#include <math.h>
int nStep = 0;
GLfloat lightAmbient[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat lightDiffuse[] = { 0.7f, 0.7f, 0.7f, 1.0f };
GLfloat lightSpecular[] = { 0.9f, 0.9f, 0.9f };
GLfloat materialColor[] = { 0.8f, 0.0f, 0.0f };
GLfloat vLightPos[] = { -80.0f, 120.0f, 100.0f, 0.0f };
GLfloat ground[3][3] = { { 0.0f, -25.0f, 0.0f },
                        { 10.0f, -25.0f, 0.0f },
                        { 10.0f, -25.0f, -10.0f } };
GLuint textures[4];
void RenderScene(void)
	{
	M3DMatrix44f mCubeTransform;
	M3DVector4f pPlane;
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_NORMALIZE);

	glPushMatrix();
	glDisable(GL_LIGHTING);
	...
        ....


Cannot add complete program, there is an 8K letter limit, cannot attach files.
Hope someone can help...
Last edited on
I think you need to link to OpenGL.

-lOGL
-lGL
-lgl

I think may work, try them out in project(right click) -> build options -> linker settings -> other linker options
Hello Bourgond,

I added the compiler options to the place you mentioned, but my IDE gives an error:


-------------- Clean: Debug in Test_OpenGL (compiler: GNU GCC Compiler)---------------

Cleaned "Test_OpenGL - Debug"

-------------- Build: Debug in Test_OpenGL (compiler: GNU GCC Compiler)---------------

mingw32-g++.exe -Wall -g -ID:\freeglut\include -c "D:\Codeblock C files\Test_OpenGL\main.cpp" -o obj\Debug\main.o
mingw32-g++.exe -LD:\freeglut\lib -o bin\Debug\Test_OpenGL.exe obj\Debug\main.o -lOGL -lGL -lgl -lglut32 -lopengl32 -lglu32 -lwinmm -lgdi32
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot find -lOGL
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot find -lGL
c:/mingw/bin/../lib/gcc/mingw32/4.7.2/../../../../mingw32/bin/ld.exe: cannot find -lgl


Other information that might be usefull, after seing the error:
My glut / freeglut folder is located in D:\freeglut, containing the folders:
- include
- lib

Looks like the IDE is searching in the wrong directory.... is that correct and what can I do?

Edit: wait a minute..... Looks like this might be part of the solution:
http://www3.ntu.edu.sg/home/ehchua/programming/opengl/HowTo_OpenGL_C.html

I must honestly say....OpenGL setup is really difficult and not well documented....
So many bits and pieces scattered around Internet-net...
Of course, that might be my problem, lacking proper searching skills??
Trying the suggestion in the link... in the meantime, if there is more to know about it, that I should know, post please. thanks...

Edit:
-- download the MingW package as mentioned.
http://www.transmissionzero.co.uk/software/freeglut-devel/

-- Both mingW package readme.txt and website link mention that I have to copy the just unpacked folders to MingW:
Because My Codeblocks+MingW package has installed everything already I copy the files
to the existing folders:
- C:\MinGW\freeglut\lib
- C:\MinGW\freeglut\include


-- Trying to compile: no change, same errors

-- trying the compiler switches mentioned in the MingW package from Transmissionzero
read me. I added the following switches to Codeblocks project build options, linker settings:

-D FREEGLUT_STATIC -I"C:\MinGW\freeglut\include"
-L"C:\Program Files\Common Files\MinGW\freeglut\lib"
-lfreeglut_static
-lopengl32
-lwinmm
-lgdi32
-Wl,--subsystem,windows

Results: errors decreased to 8 and as follows:

obj\Debug\main.o||In function `Z11RenderScenev':|
D:\Codeblock C files\Test_OpenGL\main.cpp|168|undefined reference to `m3dGetPlaneEquation(float*, float const*, float const*, float const*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|169|undefined reference to `m3dMakePlanarShadowMatrix(float*, float const*, float const*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|234|undefined reference to `m3dGetPlaneEquation(float*, float const*, float const*, float const*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|235|undefined reference to `m3dMakePlanarShadowMatrix(float*, float const*, float const*)'|
obj\Debug\main.o||In function `Z7SetupRCv':|
D:\Codeblock C files\Test_OpenGL\main.cpp|268|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|278|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|288|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|298|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
||=== Build finished: 8 errors, 0 warnings (0 minutes, 1 seconds) ===|



Last edited on

Again, I am stuck. trying to look for info about: "m3dGetPlaneEquation"....
http://www.linuxquestions.org/questions/programming-9/what-does-undefined-reference-to-mean-when-using-gcc-299990/

http://stackoverflow.com/questions/924485/whats-the-difference-between-a-header-file-and-a-library

So I am missing a library or header file..... But which....??

Edit:

m3dGetPlaneEquation seems to be a function that is mentioned in math3d.h

The OpenGL Super Bible includes a zip file with a shared folder, I remember, in which is the math3d.h file. And it has many header files and one library file. Copying *.lib to
C:\MinGW\freeglut\lib and *.h files to C:\MinGW\freeglut\include

-- trying to compile....nothing changed , same 8 errors...
Last edited on
It looks like you're failing to link against the gltools library.

The following looked helpful. It's a different edition, but it should work out roughly the same.
http://stackoverflow.com/questions/5608520/opengl-superbible-5th-edition-set-up-problems

Found this : http://stackoverflow.com/questions/2033800/i-cant-link-my-opengl-program-to-math3d-h afetr searching on google with the words: math3d.h opengl

That makes sense now.... How can I use a "phonebooks telephone number" (Header file) if "the person" (Library file) has moved or does not exist any longer??

Trying to compile math3d.cpp and add library to C:\MinGW\lib

The compile steps mentioned in link, are not working properly for me...
Found this: http://stackoverflow.com/questions/5947067/how-to-create-a-static-library-with-g

Used mingW shell to compile it....

Now I created a math3d.a library file....
Last edited on
Trying to link it, found this website: http://www.delorie.com/djgpp/v2faq/faq8_22.html
Not going to rename it, just use it as it is, like math3d.a

Linking it, in Colorblocks I did:
Right mouse on project, build options, linker settings, under "link libraries" press "add"
, navigate to c:\mingw and select my library.

Results: 4 errors ... small smile.... =)

Resulting errors:
obj\Debug\main.o||In function `Z7SetupRCv':|
D:\Codeblock C files\Test_OpenGL\main.cpp|269|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|279|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|289|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
D:\Codeblock C files\Test_OpenGL\main.cpp|299|undefined reference to `gltLoadTGA(char const*, int*, int*, int*, unsigned int*)'|
||=== Build finished: 4 errors, 0 warnings (0 minutes, 1 seconds) ===|

Searching info for "gltLoadTGA" .....

Edit: http://www.opengl.org/discussion_boards/showthread.php/165911-Texture-Mapping

In my code I have the line: #include "gltools.h", this means I lack the library file....
Last edited on
Those functions are part of the same gltools library as math3d, although it looks like it may be called gltReadTGABits in the 5th edition. There are some archived versions you can find through google.

Trying to comple, then convert to library file again, but now the gltools.cpp file.
In MingW shell

$ g++ -c gltools.cpp
gltools.cpp: In function 'GLhandleARB gltLoadShaderPair(const char*, const char*
)':
gltools.cpp:624:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]
gltools.cpp:631:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]
gltools.cpp:644:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]
gltools.cpp:652:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]

Edit: fast fix, googled for gltools.lib

-- this one doesn't work correct, reason unknown.
http://code.google.com/p/oglsuperbible5/source/browse/trunk/VisualStudio2008/GLTools/Release/gltools.lib?r=122

-- trying this gltools.lib file
http://www.scribd.com/doc/39175015/Setting-Up-Freeglut-and-GLTools-Libraries-Visual-Studio-2010

points me too: http://gamedev.dlivingstone.com/2010/10/01/freeglut/
Then to: https://www.box.com/shared/dc1zznhdt4
Last edited on

Copied the header files that were supplied with this last download, towards
c:\mingw\include

Latest error:
D:\Codeblock C files\Test_OpenGL\main.cpp||In function 'void SetupRC()':|
D:\Codeblock C files\Test_OpenGL\main.cpp|269|error: 'gltLoadTGA' was not declared in this scope|
||=== Build finished: 1 errors, 0 warnings (0 minutes, 1 seconds) ===|

What does "was not declared in this scope" mean?

Edit: The function is defined / initiated somewhere and has ended or cannot be accessed from the place it is called....

Google with words " 'gltLoadTGA' was not declared in this scope"
Gave link http://cplusplus.syntaxerrors.info/index.php?title=%E2%80%98cout%E2%80%99_was_not_declared_in_this_scope

I guess the gltools.lib is not linked correctly.

I copied the file again, re-linked in build options.
Result error: gltools.lib: no such file or directory....

What is this??? Why???

????
Last edited on

Found this: http://forums.codeblocks.org/index.php?topic=14212.0;prev_next=prev

Trying... Added c:\mingw\lib to build search.

Gettings errors like:

C:\MinGW\lib\gltools.lib|2|error: stray '`' in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|
C:\MinGW\lib\gltools.lib|3|error: stray '\24' in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|
C:\MinGW\lib\gltools.lib|3|error: stray '\6' in program|
C:\MinGW\lib\gltools.lib|3|error: stray '\344' in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|
C:\MinGW\lib\gltools.lib|3|error: stray '\6' in program|
C:\MinGW\lib\gltools.lib|3|error: stray '\344' in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|
C:\MinGW\lib\gltools.lib|3|error: stray '\6' in program|
C:\MinGW\lib\gltools.lib|3|error: stray '\344' in program|
C:\MinGW\lib\gltools.lib|3|warning: null character(s) ignored [enabled by default]|

||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 25 warnings (6 minutes, 21 seconds) ===|



Last edited on
Thanks Cire....will have a look....for archived version 4 of gltools.lib....

I found the copy of 4th edition. It's the file gltools.cpp that gives the previous errors if
I execute $ g++ -c gltools.cpp under mingw shell with windows 7:

gltools.cpp: In function 'GLhandleARB gltLoadShaderPair(const char*, const char*
)':
gltools.cpp:624:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]
gltools.cpp:631:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]
gltools.cpp:644:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]
gltools.cpp:652:16: warning: converting to non-pointer type 'int' from NULL [-Wc
onversion-null]

I have no clue how to solve this....downloading a pre-compiled versions seems not to work also.... then get the errors from previous reply....
Last edited on
@cire: Freeglut is working fine, I can compile and run a simple OpenGL animation.
No need to re-compile, because I am using the allready compiled package for MingW.
But I did try to compile gltools.cpp as said in your link, but changed it to G++ and *.cpp:
$ g++ -O2 -c -DFREEGLUT_STATIC *.cpp

With version 4 of the file gltools.cpp, I get the errors:
gltools4.cpp: In function 'bool gltGetOpenGLVersion(int&, int&)':
gltools4.cpp:18:50: error: new declaration 'bool gltGetOpenGLVersion(int&, int&)
'
In file included from gltools4.cpp:10:0:
c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/gltools.h:144:6: error
: ambiguates old declaration 'void gltGetOpenGLVersion(GLint&, GLint&)'
gltools4.cpp: In function 'void gltDrawTorus(GLfloat, GLfloat, GLint, GLint)':
gltools4.cpp:277:30: error: 'm3dNormalizeVector' was not declared in this scope
gltools4.cpp: In function 'GLhandleARB gltLoadShaderPair(const char*, const char
*)':
gltools4.cpp:624:16: warning: converting to non-pointer type 'GLhandleARB {aka u
nsigned int}' from NULL [-Wconversion-null]
gltools4.cpp:631:16: warning: converting to non-pointer type 'GLhandleARB {aka u
nsigned int}' from NULL [-Wconversion-null]
gltools4.cpp:644:16: warning: converting to non-pointer type 'GLhandleARB {aka u
nsigned int}' from NULL [-Wconversion-null]
gltools4.cpp:652:16: warning: converting to non-pointer type 'GLhandleARB {aka u
nsigned int}' from NULL [-Wconversion-null]


Any idea why?
Last edited on
Topic archived. No new replies allowed.