I still dont manage to do this… I can make the dictionary, link it and compile it, but it crashed when trying to create a TBranch using the class “numbers”. I would be very grateful if someone could give me a hint what to do
I have a class header and source file (number.hpp/cpp) and a main file test.cpp where the class is used (see below). I create the dictionary using
rootcint -f mydict.cpp numbers.hpp LinkDef.h
then compile and and link the result with the main file (I include the mydict.hpp in the main file, correct?). I have included the Makefile below. This works without errors, but when I execute the executable I get a segmentation violation at the point in the code when the Branch is created (which uses the class “numbers”). This is where Im stuck. If anybody have a clue, please tell me.
cheers
/Mett
//header file
#include <TObject.h>
#ifndef NUMBERS_H
#define NUMBERS_H
class numbers
{
public:
numbers();
~numbers();
int one;
int two;
int three;
ClassDef(numbers,1);
};
#endif
// main file
#include <stdio.h>
#include <stdlib.h>
#include <TTree.h>
#include <TFile.h>
#include “mydict.h”
#include “numbers.hpp”
int main()
{
numbers g;
TFile *f = new TFile(“mytree.root”,“recreate”);
TTree *t = new TTree(“t”,“my test tree”);
t->Branch(“my branch”,“numbers”,&g,10000,0);
g.one = 1;
g.two = 2;
g.three = 3;
t->Fill();
t->Write();
f->Close();
delete f;
delete t;
return 1;
}
CC = g++
CFLAGS = -fPIC
ALL_CFLAGS = -Wall -O6 $(CFLAGS)
LIBS = -L/nfs/d22/hfm/hess/Base_Software_Linux64_gcc4.1c/usr/lib/root -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -pthread -lm -ldl -rdynamic
INCS = -I/nfs/d22/hfm/hess/Base_Software_Linux64_gcc4.1c/usr/include/root/
EXE = test.exe
%.o : %.cpp Makefile
$(CC) $(ALL_CFLAGS) $(INCS) -c $< -o $@
all: $(EXE)
OBJS = mydict.o numbers.o test.o
$(EXE): $(OBJS) Makefile
$(CC) $(ALL_CFLAGS) $(INCS) $(OBJS) $(LIBS) -o $(EXE)
.PHONY : clean
clean:
rm -f *.o *.exe
[quote=“pcanal”]Hi,
You need to generate the dictionary for the class ‘numbers’. See the User’s guide for details (i.e. you will need to use rootcint -f mydict.cxx -c myheader.h mylinkdef.h and compile and link the result) or simply load your whole file using ACLiC into root (i.e. rather than calling the compiler yourself simply doroot [] .L myscript.C+
ACLiC will take care of running rootcint, the compiler and the linker for you.
Cheers,
Philippe.[/quote]