demonking
demonking

Reputation: 2654

Makefile with relative paths?

I have a problem with my Makefiles on Gentoo Linux.

Here is my folder hierarchy:

Development
 -> GLTools  
   -> include    
   -> src

->Triangle    
  ->triangle.cpp    
  ->Makefile

and my Makefile:

MAIN = triangle
SRCPATH = ./
SHAREDPATH = ../GLTools/src/
SHAREDINCPATH = ../GLTools/include/
LIBDIRS = -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 = -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 $(SRCPATH)$(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

My problem is that get the following error:

demonking@Master ~/Development/Triangle $ make
g++    -c -o triangle.o triangle.cpp
triangle.cpp:4:50: error: GLTools.h: No such file or directory
triangle.cpp:5:56: error: GLShaderManager.h: No such file or directory

But when I copy my Makefile to the folder Development (a folder up one level) and edit my paths it compiles without any errors.

Why do I get an error when my triangle.cpp and Makefile are in one folder and I try to access GLTools in the parent folder?

Upvotes: 6

Views: 15666

Answers (2)

Michał Šrajer
Michał Šrajer

Reputation: 31182

Try set flags for g++

CXXFLAGS = $(CFLAGS)

Upvotes: 1

The default rule for compiling c++ uses CXXFLAGS rather than CFLAGS, and you haven't set it so it does not include INCDIRS.

Add

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

and try again.

The way you would have spotted this yourself is by reading the output of make. Notice the first line in the output you exhibit:

g++    -c -o triangle.o triangle.cpp

No include flags. No -g. None of the stuff that you took all the trouble to set up.

Upvotes: 4

Related Questions