undefined reference

Hello forum,

I have included the following class file which is located in another directory. The Makefile specifies the inclusion path to the file . But i get the undefined reference error when i try to use any functions from this file i included

1
2
3
4
5
6
7
8
9
10
11
12
13
#ifndef GLUTILS_H
#define GLUTILS_H

class GLUtils
{
public:
    GLUtils();

    static int checkForOpenGLError(const char *, int);
    static void dumpGLInfo(bool dumpExtensions = false);
};

#endif // GLUTILS_H 


The corresponding the .cpp file defines the function declaration i have above.

And the error i get is as follows:

1
2
3
4
5
6
7
8
g++ -O2 -g -o basicshader main.o scenebasic.o scenebasic_layout.o scenebasic_uniformblock.o scenebasic_uniform.o -lGLEW -lglut -lGL -lXmu -lX11 -lm 
main.o: In function `paintGL()':
/home/sajjad/Documents/Books/OpenGL/ShaderCookBook/glslcookbook-master/chapter01/main.cpp:36: undefined reference to `GLUtils::checkForOpenGLError(char const*, int)'
main.o: In function `initializeGL()':
/home/sajjad/Documents/Books/OpenGL/ShaderCookBook/glslcookbook-master/chapter01/main.cpp:27: undefined reference to `GLUtils::dumpGLInfo(bool)'
collect2: ld returned 1 exit status
make: *** [all] Error 1


What am i doing wrong here?


Thanks
Sajjad
Check the path to your object files. The .cpp file in the other directory was presumably compiled, but the linker can't find it. The linker has to know how to find the object file in the other directory.
Hi

I know it is not for the Makefile issue, but i could not get it around . Here goes the makefile , i hope to get some more hint on this, because the error still prevails:

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

GL_INGREDIENTS_PATH = $(HOME)/Documents/Books/OpenGL/ShaderCookBook/glslcookbook-master/ingredients

CC = g++
CFLAGS = -O2 -g
INCLUDE = -I/usr/local/cuda/include
INCLUDE += -I/usr/local/include/glm
INCLUDE += -I$(HOME)/Documents/Books/OpenGL/ShaderCookBook/glslcookbook-master/ingredients
LDFLAGS = -L$(GL_INGREDIENTS_PATH) -lGLEW -lglut -lGL -lXmu -lX11 -lm 
COBJS = $(patsubst %.cpp,%.o,$(wildcard *.cpp))


EXE= basicshader

all: $(COBJS) 
	$(CC) $(CFLAGS) -o $(EXE) $(COBJS) $(LDFLAGS)

%.o : %.cpp 
	$(CC) $(CFLAGS) -o $@ -c $< $(INCLUDE) 


clean:
	rm -f $(EXE) *.o *~




I am providing the linker path as follows:

 
LDFLAGS = -L$(GL_INGREDIENTS_PATH)



Anything still missing?


Regards
Sajjad
You are not linking against `glutils.o'
Topic archived. No new replies allowed.