Compiling error with makefile

Hello,

first of all, I’ve got a macro “file.cxx”. Most of the time I just let root interpret it. Therefore I need to load AtlasStyle and a file which was created because I used MakeClass. So in the terminal I start root and than .L AtlasStyle.C and .L myclass.C.
Now I want to compile the macro, and I made a makefile. Since this is my first one, I’ve got a few problems.
This is my makefile:

CFLAGS	=	$(shell root-config --cflags)
LIBS	        =	$(shell root-config --libs)
GLIBS	=	$(shell root-config --glibs)

all:	macro

clean:
	rm -f *.o macro

macro     :	macro.o	myclass.o	 myheader.o #in myheader.h is a function I use defined
	g++	-o	$@	$+	$(CFLAGS)	$(LIBS)	$(GLIBS)	

myclass.o 	:	myclass.C	myclass.h
myheader.o	:	myheader.h
macro.o	:	macro.cxx	myclass.h	     myheader.h

If I type “make” in the terminal the following error occurs:

g++    -c -o myclass.o myclass.C
In file included from myclass.C:2:0:
myclass.h:11:19: fatal error: TROOT.h:File or directory not found
compilation terminated.

So, where did I do something wrong in the makefile? As I mentioned it’s the first time I work with make. And how do I load AtlasStyle.C?
I’ve also read the Root User’s Guide, and in chapter 3.4.2 there was something about compiling. Do I need a main-function in my macro?

It would be nice, if someone could say, how my makefile must look like, that it will work.

Best regards

In your “makefile”, try to define:

CXX = $(shell root-config --cxx)
CXXFLAGS = $(shell root-config --cflags)

and replace g++ with $(CXX) $(CXXFLAGS)

You may also need to define a new rule:

%.o : %.C
        $(CXX) $(CXXFLAGS) -o $@ -c $<

Thank you for your help.
I did that, but now it says:

make: root-config: command not found
make: root-config: command not found
o myclass.o -c myclass.C
make: o: command not found

So, now I made make clean. And then run make again. This time it says:

g++ -pthread -m64 -I/usr/include/root	-o	myclass.o	 -c	myclass.C
In file included from myclass.C:2:
myclass.h:28: error: ISO C++ forbids declaration of ‘vector’ with no type
myclass.h:28: error: expected ‘;’ before ‘<’ token

for every leave type in the TTree.
And

myclass.h: In member function ‘virtual void signal::Init(TTree*)’:
myclass.h:337: error: ‘Particle_PID’ was not declared in this scope

for every object pointer. I think this second error comes because of the first error. But I don’t know why there is the first error anyway…

line 28 is: vector<int> *Particle_PID;
line 337 is: Particle_PID = 0;

Edit: fixed this error with: using std::vector; at the beginning of myclass.h

The next output I get is this one:

g++ -pthread -m64 -I/usr/include/root	-o	myclass.o	-c	myclass.C
g++ -pthread -m64 -I/usr/include/root	-o	macro  macro.o myclass.o myheader.o	-pthread -m64 -I/usr/include/root	-L/usr/lib64/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic	-L/usr/lib64/root -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic
g++: macro.o: No such file or directory
g++: myheader.o: No such file or directory

Could this be, because there is no myheader.C and macro.C (only marco.cxx)?

Just don’t do it. You have spent more time on this now than necessary :slight_smile:

Simply start up ROOT, and load .L myCode.C+. This will compile the code. In ROOT 6 there is (virtually) no difference between these two.

Axel.

I have done it by now :'D So yeah, I spent way to much time for that but now it works. I just had to figure out how my files are depending on each other, so now everything is fine :slight_smile: It’s kinda hard for me to understand some of these things, because I’m doing it for the first time and it’s often “learning-by.doing” and this costs lot of time.

Thanks for all your help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.