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?
You can use shell function: current_dir = $(shell pwd) .
The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.
That's what abspath does. It creates an absolute path. That means it must be anchored at the root.
$(addprefix prefix , names …) The argument names is regarded as a series of names, separated by whitespace; prefix is used as a unit. The value of prefix is prepended to the front of each individual name and the resulting larger names are concatenated with single spaces between them.
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.
Try set flags for g++
CXXFLAGS = $(CFLAGS)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With