Makefile add include directory


it may be a dumb question but I can’t figure it out… I have a folder with a lot of .cxx and .h file and everything compile perfectly. Then I wanted to move the .h files to a ./include folder. So, after moving the .h files the folder looks like this:

Doxyfile_pmttest  ls.cxx    Makefile       oscilloscope.cxx  serial.o    spe.o
error             ls.o      Makefile.arch  oscilloscope.o    signal.cxx
guitest.o         main.cxx  open.cxx       PMT               signal.o
include           main.o    open.o         serial.cxx        spe.cxx

Then, I tried to add the include folder into the makefile which looks like this:

include Makefile.arch

CXXFLAGS +=-I/usr2/fuentes/PMTtest/include

mainO      = main.$(ObjSuf)
mainS      = main.$(SrcSuf)
main       = PMT$(ExeSuf)
openO	      = open.$(ObjSuf)
openS         = open.$(SrcSuf)
lsO	    = ls.$(ObjSuf)
lsS         = ls.$(SrcSuf)
serialO	      = serial.$(ObjSuf)
serialS         = serial.$(SrcSuf)
oscilloscopeO	      = oscilloscope.$(ObjSuf)
oscilloscopeS         = oscilloscope.$(SrcSuf)
signalO	      = signal.$(ObjSuf)
signalS         = signal.$(SrcSuf)
speO	      = spe.$(ObjSuf)
speS         = spe.$(SrcSuf)

EXE_FILES = $(main)
OBJ_FILES = $(openO) $(lsO) $(serialO) $(oscilloscopeO) $(signalO) $(speO) $(mainO) 

$(main):   $(OBJ_FILES)
		$(LD) $(LDFLAGS) $(OBJ_FILES) $(GLIBS) $(LIBS) $(OutPutOpt) $@
		@echo "$@ done"

.SUFFIXES: .$(SrcSuf)

	$(CXX) $(CXXFLAGS) -c $<

.PHONY : clean

Then, when I try to compile it fails and gives a huge error list:

fede@jenna:/usr2/fuentes/PMTtest$ make
g++ -O2 -Wall -fPIC -pthread -m32 -I/usr/include/root -I/usr2/fuentes/PMTtest/include -c open.cxx
In file included from /usr/include/c++/4.2/bits/char_traits.h:46,
                 from /usr/include/c++/4.2/string:47,
                 from /usr2/fuentes/PMTtest/include/signal.h:9,
                 from /usr/include/pthread.h:29,
                 from /usr/include/c++/4.2/i486-linux-gnu/bits/gthr-default.h:43,
                 from /usr/include/c++/4.2/i486-linux-gnu/bits/gthr.h:114,
                 from /usr/include/c++/4.2/i486-linux-gnu/bits/c++io.h:43,
                 from /usr/include/c++/4.2/iosfwd:46,
                 from /usr/include/root/Riosfwd.h:33,
                 from /usr/include/root/TObject.h:40,
                 from /usr/include/root/TNamed.h:26,
                 from /usr/include/root/TDirectory.h:25,
                 from /usr/include/root/TROOT.h:29,
                 from /usr2/fuentes/PMTtest/include/open.h:8,
                 from open.cxx:7:
/usr/include/c++/4.2/bits/stl_algobase.h:321: error: ‘ostreambuf_iterator’ was not declared in this scope
/usr/include/c++/4.2/bits/stl_algobase.h:321: error: template argument 2 is invalid
etc. etc. etc...

Could you please tell me how to add an include folder??? and a libraries folder???




Your header file /usr2/fuentes/PMTtest/include/signal.h conflict with the system header on the same name (pthread.h needs it). Rename your file and the problem will go away.


OOOHHHH I’m an idiot!!! That fixed the problem. Thanks a lot!!!


For what it’s worth, if you put your own user include files in a subdirectory and access them that way, you are less likely to be bitten by this. For example:

#include "interface/signal.h"

is safer than

#include "signal.h"

Of course, once you’ve figured out that you have the same name as a standard include file, changing the name is probably a good idea regardless. :smiley: