Hi,
I’m creating a simple program, in which I load a llibrary created using File::MakeProject.
The code is here:
[code]
#include “TFile.h”
#include “TTree.h”
#include “TMath.h”
#include “TSystem.h”
#include
#include “HptEventOld/HptEventOld.h”
#include
int main(int argc, char *argv[]){
using namespace std;
gSystem->Load("libTree");
gSystem->Load("HptEventOld/HptEventOld.so");
if (argc != 1) cout << "wrong number of arguments" << endl;
char *rootfile1="P1G_merged.root";
double Xbj, final_phi_h, final_phi_s, polarisation, FDP, phi, p1T, p1L, p2T, p2L, Q2;
int configuration;
TFile *newfile = new TFile (Form("new-%s",
rootfile1), "recreate");
TTree *newtree = new TTree("USR1","newTree");
newtree -> Branch("final_phi_h",&final_phi_h, "final_phi_h/D");
newtree -> Branch("final_phi_s",&final_phi_s, "final_phi_s/D");
newtree -> Branch("phi",&phi, "phi/D");
newtree -> Branch("Xbj",&Xbj, "Xbj/D");
newtree -> Branch("p1T",&p1T, "p1T/D");
newtree -> Branch("p2T",&p2T, "p2T/D");
newtree -> Branch("p1L",&p1L, "p1L/D");
newtree -> Branch("p2L",&p2L, "p2L/D");
newtree -> Branch("polarisation",&polarisation, "polarisation/D");
newtree -> Branch("configuration",&configuration, "configuration/I");
newtree -> Branch("FDP",&FDP, "FDP/D");
TFile *f1 = new TFile (rootfile1, “readonly”);
TTree *tree = (TTree*)f1 -> Get("USR1");
HptEventOld *p=0;
tree->SetBranchAddress("Event",&p);
Long64_t nn = tree -> GetEntries();
for (Long64_t j=0; j<1000; j++){
tree -> GetEntry(j);
if (p->vCell==1) configuration=0;
if (p->vCell==2) configuration=1;
switch (p->vCell){
case 1: FDP = p->eDf_u;
polarisation = p->ePolu;
break;
case 2: FDP = p->eDf_d;
polarisation = p->ePold;
break;
}
final_phi_h = p->hPhi_h;
final_phi_s = p->hPhi_s;
phi= final_phi_h - final_phi_s;
if (phi>TMath::TwoPi()) phi-=TMath::TwoPi();
if (phi<0.0) phi+=TMath::TwoPi();
Q2 = p->kQ2;
Xbj= p->kXbj;
p1T = p->hPt[0];
p1L = p->hPl[0];
p2T = p->hPt[1];
p2L= p->hPl[1];
newtree->Fill();
}
tree->ResetBranchAddresses();
newfile -> cd();
newtree -> Write();
newfile -> Close();
}[/code]
To compile I’'m using a simple Makefile which is below
[code]
CC = gcc
CPPFLAGS = (shell {ROOTSYS}/bin/root-config --cflags)
LDFLAGS = (shell {ROOTSYS}/bin/root-config --libs) -lXMLParser
INCS = HptEventOld/HptEventOld.h
OBJS = tree.o HptEventOld/HptEventOld.so
#all: eventview
run_prog: (OBJS) (CC) -o run_prog (OBJS) (CPPFLAGS) $(LDFLAGS)
tree.cc: $(INCS)
clean:
rm -f .*~ *~ *.bak .o run_prog. .depend run_prog[/code]
The code compiles fine:
$ make clean
rm -f .*~ *~ *.bak *.o run_prog.* .depend run_prog
[lsilva@ccage016 simple_prog]$ make
g++ -pthread -m64 -I/usr/local/root/v5.34.14/include -c -o tree.o tree.cc
tree.cc: In function 'int main(int, char**)':
tree.cc:26: warning: deprecated conversion from string constant to 'char*'
gcc -o run_prog tree.o HptEventOld/HptEventOld.so -pthread -m64 -I/usr/local/root/v5.34.14/include -L/usr/local/root/v5.34.14/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lXMLParser
The error is at the runtime level:
$./run_prog
./run_prog: error while loading shared libraries: HptEventOld.so: cannot open shared object file: No such file or directory
I’m pretty sure that it is some mistake that I’m doing at the level of the compilation in the Makefile. Because I’ve tested the code in Cint as a rootscript.
Can someone please have a look?
Many thanks in advance.
Regards,
Luís.
P1G.root (70.3 KB)