Event class in standalone compiled code

Hi All,
I would like to use the Event class resources but I find that I need to compile these libraries explicitly in my makefile before I can use them. I am using Linux. Can anyone provide a barebones example of a function that makes use of the Event class, and the makefile that will compile it? Something like myFunc.cpp looking like below

#include "all_the_headers.h"

int main(){
// make a tree
TTree t4("t4","A Tree with Events");
 // create a pointer to an Event object
Event *event = new Event();
 // create two branches, split one
t4.Branch("event_branch", "Event", &event,16000,2);
t4.Branch("event_not_split", "Event", &event,16000,0);
return 0;
}

and a makefile sort of like below:

# configure ROOT
ROOTINC         :=$(shell $(ROOTSYS)/bin/root-config --incdir)
ROOTLIBDIR     :=$(shell $(ROOTSYS)/bin/root-config --libdir)
ROOTLDFLAGS  :=$(shell $(ROOTSYS)/bin/root-config --ldflags)
ROOTCFLAGS := $(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS   := $(shell  $(ROOTSYS)/bin/root-config --libs)
ROOTLINK    =-L$(ROOTLIBDIR) $(ROOTLIBS) $(ROOTLDFLAGS) $(ROOTCFLAGS)
EVENTO       = Event.o EventDict.o
EVENTS       = Event.cxx EventDict.cxx
EVENTSO     = libEvent.so
EVENT         = Event
EVENTLIB     = $(shell pwd)/$(EVENTSO)

default: all

all: $(EVENT) myFunc
	
myFunc: $(EVENT) myFunc.cpp
	g++ -O -Wall -o myFunc myFunc.cpp
	$(ROOTLINK)
	
 $(EVENTSO): $(EVENTO)
 	blah blah blah
 $(EVENT):  $(EVENTSO)
	blah blah blah

${ROOTSYS}/test/Event.[hc]*
${ROOTSYS}/test/Makefile

That makefile is over 800 lines long, using Cmake-style makefile.arch headers. It is extremely turgid. Respectfully, can anyone supply a barebones makefile that compiles the Event class.

Have a look at https://root.cern.ch/how/integrate-root-my-project-cmake The used example is the Event class.

Thanks for that! I will try to understand this.

wrongly replied instead of edited

[quote=“mgv4ce”]I am trying to migrate to a Cmake method. But understanding Cmake needs an understanding of Make. I do not understand what I am doing wrong.

#include "constants.h"
#include "Event.h"

int main(){
 //make a tree
 TTree t4("t4","A Tree with Events");
  // create a pointer to an Event object
  //Event *event = new Event();
   // create two branches, split one
   //t4.Branch("event_branch", "Event", &event,16000,2);
   //t4.Branch("event_not_split", "Event", &event,16000,0);
   return 0;
   }

I know that the program does not use Event. First I try to get Event to compile. I think the Makefile below should work but it does not:

#-----------configure ROOT-----------#
ifdef ROOTSYS
include $(ROOTSYS)/etc/Makefile.arch 
ROOTINC     :=$(shell $(ROOTSYS)/bin/root-config --incdir)
ROOTLIBDIR  :=$(shell $(ROOTSYS)/bin/root-config --libdir)
ROOTLDFLAGS :=$(shell $(ROOTSYS)/bin/root-config --ldflags)
ROOTCFLAGS  :=$(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS    := $(shell  $(ROOTSYS)/bin/root-config --libs) 
ROOTLINK = $(ROOTLIBS) $(ROOTCFLAGS) $(ROOTLDFLAGS) -I$(ROOTINC)
else 
@echo "NO ROOTSYS!"
endif

#--------configure compiler----------#
CXX      = g++
CFLAGS   = $(ROOTLINK) 
CFLAGS  += -O2 -Wall -Wno-write-strings
LIBS     = -lm -lz -lutil -lnsl -lpthread
 
.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)

#----------configure the Event class-----------#
EVENTO    = Event.$(ObjSuf) EventDict.$(ObjSuf)
EVENTS    = Event.$(SrcSuf) EventDict.$(SrcSuf)
EVENTSO   = libEvent.$(DllSuf)
EVENT     = Event$(ExeSuf)
EVENTLIB  = $(shell pwd)/$(EVENTSO)
MAINEVENTO  = MainEvent.$(ObjSuf)
MAINEVENTS  = MainEvent.$(SrcSuf)

#--------object declaration----------#
OBJECTS  := $(EVENTO)
#OBJECTS += $(MAINEVENTO)
SHAREDOBJECTS = $(EVENTSO)

default: all

all: main

$(EVENTSO):     $(EVENTO)
		$(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ $(EXPLLINKLIBS)
		@echo "$@ done"

$(EVENT):       $(EVENTSO) $(MAINEVENTO)
		$(LD) $(LDFLAGS) $(MAINEVENTO) $(EVENTO) $(LIBS) $(OutPutOpt)$@
		$(MT_EXE)
		@echo "$@ done"

Event.$(ObjSuf): Event.h
MainEvent.$(ObjSuf): Event.h

EventDict.$(SrcSuf): Event.h EventLinkDef.h
	@echo "Generating dictionary $@..."
	$(ROOTCINT) -f $@ -c $^

.$(SrcSuf).$(ObjSuf):
	@echo "Compiling $@"
	$(CXX) $(CFLAGS) -c $<
	@echo "-----------------------------------------------------"
	
main: main.cxx $(EVENT)
	$(CXX) $(CFLAGS) -o myApp main.cxx 
	@echo "-----------------------------------------------------"

clean::
	rm -f *.o *~ \#*
	@rm -f $(OBJECTS) core
	rm -f $(PROGRAMS)

The output is:


g++ -L/common/lib/root-5.34.23/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic  -pthread -m32 -I/common/lib/root-5.34.23/include -m32 -I/common/lib/root-5.34.23/include  -O2 -Wall -Wno-write-strings -c Event.cxx
-----------------------------------------------------
Compiling EventDict.o
g++ -L/common/lib/root-5.34.23/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic  -pthread -m32 -I/common/lib/root-5.34.23/include -m32 -I/common/lib/root-5.34.23/include  -O2 -Wall -Wno-write-strings -c EventDict.cxx
-----------------------------------------------------
c++ -shared -O2 -m32 Event.o EventDict.o -o  libEvent.so 
libEvent.so done
Compiling MainEvent.o
g++ -L/common/lib/root-5.34.23/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic  -pthread -m32 -I/common/lib/root-5.34.23/include -m32 -I/common/lib/root-5.34.23/include  -O2 -Wall -Wno-write-strings -c MainEvent.cxx
-----------------------------------------------------
c++ -O2 -m32 MainEvent.o Event.o EventDict.o -lm -lz -lutil -lnsl -lpthread -o Event
MainEvent.o: In function `global constructors keyed to main':
MainEvent.cxx:(.text+0x3e): undefined reference to `TVersionCheck::TVersionCheck(int)'
MainEvent.o: In function `main':
MainEvent.cxx:(.text+0x1a2): undefined reference to `TStopwatch::TStopwatch()'

Can anyone explain what I am missing in my Makefile?[/quote]

I was able to resolve my problem. Here is the makefile and program if anyone is interested.

Makefile is:

#-----------configure ROOT-----------#
ifdef ROOTSYS
include $(ROOTSYS)/etc/Makefile.arch 
ROOTINC     :=$(shell $(ROOTSYS)/bin/root-config --incdir)
ROOTLIBDIR  :=$(shell $(ROOTSYS)/bin/root-config --libdir)
ROOTLDFLAGS :=$(shell $(ROOTSYS)/bin/root-config --ldflags)
ROOTCFLAGS  :=$(shell $(ROOTSYS)/bin/root-config --cflags)
ROOTLIBS    := $(shell  $(ROOTSYS)/bin/root-config --libs) 
ROOTLINK = $(ROOTLIBS) $(ROOTCFLAGS) $(ROOTLDFLAGS) -I$(ROOTINC)
else 
@echo "NO ROOTSYS!"
endif

#--------configure compiler----------#
CXX      = g++
CFLAGS   = $(ROOTLINK) 
CFLAGS  += -O2 -Wall -Wno-write-strings
LIBS     = -lm -lz -lutil -lnsl -lpthread
 
.SUFFIXES: .$(SrcSuf) .$(ObjSuf) .$(DllSuf)

#----------configure the Event class-----------#
EVENTO    = Event.$(ObjSuf) EventDict.$(ObjSuf)
EVENTS    = Event.$(SrcSuf) EventDict.$(SrcSuf)
EVENTSO   = libEvent.$(DllSuf)
EVENT     = Event$(ExeSuf)
EVENTLIB  = $(shell pwd)/$(EVENTSO)
#MAINEVENTO  = MainEvent.$(ObjSuf)
#MAINEVENTS  = MainEvent.$(SrcSuf)

PROGRAMS= myApp

#--------object declaration----------#
OBJECTS  := $(EVENTO)
#OBJECTS += $(MAINEVENTO)
SHAREDOBJECTS = $(EVENTSO)

default: all

all: $(PROGRAMS)

$(EVENTSO):     $(EVENTO)
		@echo "compiling $@"
		$(LD) $(SOFLAGS) $(LDFLAGS) $^ $(OutPutOpt) $@ $(EXPLLINKLIBS)
		@echo "$@ done"
		@echo "----------------------------------"

$(EVENT):       $(EVENTSO)
		@echo "compiling $@"
		$(LD) $(ROOTLINK) $(LDFLAGS) $(EVENTO) $(LIBS) $(OutPutOpt)$@
		$(MT_EXE)
		@echo "$@ done"
		@echo "----------------------------------"

Event.$(ObjSuf): Event.h

EventDict.$(SrcSuf): Event.h EventLinkDef.h
	@echo "Generating dictionary $@..."
	@rootcint -f $@ -c $^
	@echo "$@ done"
	@echo "-------------------------------"

.$(SrcSuf).$(ObjSuf):
	@echo "Compiling $@"
	$(CXX) $(CFLAGS) -c $<
	@echo "-----------------------------------------------------"

myApp: myApp.cxx $(OBJECTS) $(SHAREDOBJECTS)
	@echo "Comiling myApp"
	$(CXX) $(CFLAGS) -o myApp myApp.cxx $(OBJECTS) $(SHAREDOBJECTS) 
	@echo "-----------------------------------------------------"

clean::
	rm -f *.o *~ \#*
	@rm -f $(OBJECTS) core
	@rm -f $(SHAREDOBJECTS) core
	rm -f $(PROGRAMS)

Executable is:


#include "headers.h"
#include "Event.h"

int main(){
 //make a tree
 TTree t4("t4","A Tree with Events");
  // create a pointer to an Event object
  Event *event = new Event();
   // create two branches, split one
   //t4.Branch("event_branch", "Event", &event,16000,2);
   //t4.Branch("event_not_split", "Event", &event,16000,0);
   return 0;
   }