Error while loading shared libraries: <share-library>.so


I’m creating a simple program, in which I load a llibrary created using File::MakeProject.

The code is here:

#include “TFile.h”
#include “TTree.h”
#include “TMath.h”
#include “TSystem.h”
#include “HptEventOld/HptEventOld.h”

int main(int argc, char *argv[]){

using namespace std;

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;


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;
  case 2: FDP = p->eDf_d;
    polarisation = p->ePold;

  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];



newfile -> cd();
newtree -> Write();
newfile -> Close();


To compile I’'m using a simple Makefile which is below

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/

#all: eventview

run_prog: (OBJS) (CC) -o run_prog (OBJS) (CPPFLAGS) $(LDFLAGS) $(INCS)

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 In function 'int main(int, char**)': warning: deprecated conversion from string constant to 'char*' gcc -o run_prog tree.o HptEventOld/ -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: 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? :neutral_face:

Many thanks in advance.

P1G.root (70.3 KB)


probably there is a mistake in your setup.
The library is not found by root when it tries to dynamically load it. Does it exist? In which directory? Is this directory in the LD_LIBRARY_PATH?