Ben Kushigian
Ben Kushigian

Reputation: 295

make not searching in include path

I'm working through an OpenGL tutorial (OpenGL SuperBible 5) and I'm trying to get the supplied Makefile to work for my own program. I'm trying to get make to access a header file GLTools.h in my /home/ben/lib/GLTools/include/ directory and I'm including it in my Makefile with -I/home/ben/lib/GLTools/include/ (actually I'm using -I$(SHAREDINCPATH)) but make complains that there is no such file. Here is my Makefile (I've explicitly mentioned where I have edited the original Makefile):

MAIN = Triangle
SRCPATH = ./      # Edited: src is in CWD
SHAREDPATH = /home/ben/lib/GLTools/src/ # Edited to copied GLTools/src dir
SHAREDINCPATH = /home/ben/lib/GLTools/include/ # Edited to copied dir
LIBDIRS = -L/usr/X11R6/lib -L/usr/X11R6/lib64 -L/usr/local/lib
INCDIRS = -I/usr/include -I/usr/local/include -I/usr/include/GL -I$(SHAREDINCPATH)  -I$(SHAREDINCPATH)GL

CC = g++
CFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
LIBS = -lX11 -lglut -lGL -lGLU -lm

prog : $(MAIN)

$(MAIN).o : $(SRCPATH)$(MAIN).cpp
glew.o    : $(SHAREDPATH)glew.c
GLTools.o    : $(SHAREDPATH)GLTools.cpp
GLBatch.o    : $(SHAREDPATH)GLBatch.cpp
GLTriangleBatch.o    : $(SHAREDPATH)GLTriangleBatch.cpp
GLShaderManager.o    : $(SHAREDPATH)GLShaderManager.cpp
math3d.o    : $(SHAREDPATH)math3d.cpp

$(MAIN) : $(MAIN).o glew.o
    $(CC) $(CFLAGS) -o $(MAIN) $(LIBDIRS) $(SRCPATH)$(MAIN).cpp $(SHAREDPATH)glew.c $(SHAREDPATH)GLTools.cpp $(SHAREDPATH)GLBatch.cpp $(SHAREDPATH)GLTriangleBatch.cpp $(SHAREDPATH)GLShaderManager.cpp $(SHAREDPATH)math3d.cpp $(LIBS)

clean:
    rm -f *.o

...and here is the make complaint:

ben@crunchbang:~/Code/C++/OpenGL/SuperBible5/SB5/Listings$ make
g++    -c -o Triangle.o Triangle.cpp
Triangle.cpp:4:50: fatal error: GLTools.h: No such file or directory
compilation terminated.
make: *** [Triangle.o] Error 1

As a sanity check I'm printing out the location of GLTools.h:

ben@crunchbang:~/Code/C++/OpenGL/SuperBible5/SB5/Listings$ ls /home/ben/lib/GLTools/include/
GL             GLFrame.h              GLMatrixStack.h    GLTriangleBatch.h
GLBatchBase.h  GLFrustum.h            GLShaderManager.h  math3d.h
GLBatch.h      GLGeometryTransform.h  GLTools.h          StopWatch.h

Any idea why I cannot compile? I am pointing right at the GLTools.h with INCDIRS, right?

Also, I cannot find a declaration of COMPILERFLAGS anywhere in the makefile -- is this system-defined?

Upvotes: 1

Views: 185

Answers (1)

user184968
user184968

Reputation:

for g++ you need to define in your makefile

CXXFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)

And since you use both C files and C++ files then define both in your makefile:

CFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)
CXXFLAGS = $(COMPILERFLAGS) -g $(INCDIRS)

CFLAGS is used by make when it compiles C files, CXXFLAGS is used when make compiles C++ files. See http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html

CFLAGS

    Extra flags to give to the C compiler.
CXXFLAGS

    Extra flags to give to the C++ compiler.

Upvotes: 1

Related Questions