Problem with standalone application and shared librairy

Dears rooters,

I’am desperatly trying to make a standalone application including a shared librairy. This is the procedure I followed to compile the shared librairy :
rootcint -f eventwaveform.cpp -c TWaveForm.hh waveform_LinkDef.h
g++ -fPIC -I/usr/include/root -o eventwaveform.o eventwaveform.cpp -c
g++ -fPIC -I/usr/include/root -o TWaveForm.o TWaveForm.cpp -c
g++ -o waveform.so -shared TWaveForm.o eventwaveform.o

But when I try to build the final application following this command line : g++ -Wall -I/usr/include/root -L/usr/lib shapeanalysis.cpp waveform.so -o shapeanalysis.exe, I can read the following error message :
shapeanalysis.cpp: In function ‘void shape_analysis()’:
shapeanalysis.cpp:171: erreur: ‘TWaveForm’ was not declared in this scope
shapeanalysis.cpp:171: erreur: ‘W_F_STD’ was not declared in this scope
shapeanalysis.cpp:171: erreur: expected type-specifier before ‘TWaveForm’
shapeanalysis.cpp:171: erreur: expected ;' before ‘TWaveForm’ shapeanalysis.cpp:184: erreur: ‘wf0’ was not declared in this scope shapeanalysis.cpp:184: erreur: expected type-specifier before ‘TWaveForm’ shapeanalysis.cpp:184: erreur: expected;’ before ‘TWaveForm’
shapeanalysis.cpp:188: erreur: ‘wf_trifouillage’ was not declared in this scope
shapeanalysis.cpp:189: erreur: ‘wf_oversampled’ was not declared in this scope
shapeanalysis.cpp:202: erreur: expected type-specifier before ‘TWaveForm’
shapeanalysis.cpp:202: erreur: expected ;' before ‘TWaveForm’ shapeanalysis.cpp:210: erreur: expected type-specifier before ‘TWaveForm’ shapeanalysis.cpp:210: erreur: expected;’ before ‘TWaveForm’
shapeanalysis.cpp:255: attention : unused variable ‘c3’
shapeanalysis.cpp:261: attention : unused variable ‘c4’

I am pretty sure that the shared librairy is well compiled because when I use it throw CINT interpreter, it is working. I am not familiar with standalone application and shared librairy, is anyone have an idea on the problem ?

Thanks in advance

Cheers

Loïc

Hi,

does shapeanalysis.cpp #include TWaveForm.hh? We will need to see shapeanalysis.cpp to be able to help you.

Cheers, Axel.

Hi Axel,

Thanks for the answer. Please see bellow the shapeanalysis.cpp file :

#include “TROOT.h”
#include “TClass.h”
#include “TGraph.h”
#include “TF1.h”
#include “TH1F.h”
#include “TH2F.h”
#include “TH3F.h”
#include “TH3D.h”
#include “TTree.h”
#include “TCanvas.h”
#include “TBranch.h”
#include “Riostream.h”
#include “TStyle.h”
#include “TFile.h”
#include “TString.h”
#include “TLegend.h”
#include “TRandom3.h”
#include “TMath.h”
#include “math.h”
#include “TColor.h”
#include “TWaveForm.hh”
#include
#include
#include

#define MAXLENGTH 10000

using namespace std;

typedef vector<Double_t> vect;

class sample{
public:
UInt_t SampleValue[128];
};

class WaveFormStd{

public:
 Int_t nb_sample_wf;
 Double_t SampleW_F[MAXLENGTH];
 Double_t T_0;	

};

void shape_analysis();

int main(){

shape_analysis();
return 0;

}

void shape_analysis()
{

//////
////////On instancie la classe des donnees d’enregistrement ////////
///
///

sample asample1;
sample asample2;
sample asample3;
WaveFormStd astdwaveform;

Double_t Nrj(0.);
Double_t Tim(0.);
Double_t Q(0.);
Double_t t_Origine(0.);
Double_t Chi2(0.);

//////
////////option d’affichage des stats des histogrammes ////////
///
///

gStyle -> SetStatW(0.28);
gStyle -> SetStatH(0.13);
gStyle -> SetStatColor(41);
gStyle -> SetStatX(0.87);
gStyle -> SetStatY(0.85);
gStyle -> SetStatFont(42);
gStyle->SetOptStat(1111111);
gStyle->SetOptFit(1111);

//////
////// Ouverture du fichier WaveForm.root //////
///
///

TFile* file=new TFile("WaveForm.root");  											
TTree * tree_wave_form = (TTree*)file->Get("Wave_Form");			
Int_t nentries = (Int_t)tree_wave_form->GetEntries();		
cout<<"nentries : "<<nentries<<endl;	

TBranch* RF_Faisceau = tree_wave_form->GetBranch("RF");
RF_Faisceau->SetAddress(&asample1);
TBranch* PMT1 = tree_wave_form->GetBranch("PM1");
PMT1->SetAddress(&asample2);
TBranch* PMT2 = tree_wave_form->GetBranch("PM2");
PMT2->SetAddress(&asample3);

//////
////// Ouverture du fichier StandardWaveForm.root //////
///
///

TFile* file_std_wf=new TFile("StandardWaveForm.root");  											

TTree * Tree_Energy_Time = (TTree*)file_std_wf->Get("Tree_Energy_Time");			
Int_t nentries_std_wf = (Int_t)Tree_Energy_Time->GetEntries();		
cout<<"nentries_std_wf : "<<nentries_std_wf<<endl;	

TBranch* Energie = Tree_Energy_Time->GetBranch("energy");
Energie->SetAddress(&Nrj);
TBranch* TempsRecal = Tree_Energy_Time->GetBranch("time");
TempsRecal->SetAddress(&Tim);
TBranch* Charge = Tree_Energy_Time->GetBranch("charge");
Charge->SetAddress(&Q);


TTree * Tree_OutPut = (TTree*)file_std_wf->Get("Tree_OutPut");			
Int_t nentries_output = (Int_t)Tree_OutPut->GetEntries();
cout<<"nentries_output : "<<nentries_output<<endl;			
TBranch* Nb_sample_std = Tree_OutPut->GetBranch("nb_sample_std");
Nb_sample_std->SetAddress(&astdwaveform.nb_sample_wf);
TBranch* Sample_STD = Tree_OutPut->GetBranch("std_waveform");
Sample_STD->SetAddress(astdwaveform.SampleW_F);
TBranch* TempsOrigine = Tree_OutPut->GetBranch("T_Origine");
TempsOrigine->SetAddress(&astdwaveform.T_0);


TFile* Chi2_File=new TFile("Chi2_File.root","recreate");
TTree* Tree_Chi2=new TTree("Tree_Chi2","A Root Tree");
Tree_Chi2->Branch("CHI2",&Chi2,"Chi2/D");

Int_t N_sample=128;
Double_t T_sampling=1.e-9;
Double_t T_samplingUp=T_sampling/5;


	
	Tree_OutPut->GetEntry(0);
	
	t_Origine=astdwaveform.T_0;
	cout<<"t_Origine "<<astdwaveform.T_0<<endl;
	Int_t Nb_Sample_std=astdwaveform.nb_sample_wf;		
	cout<<"Nb_Sample_std "<<Nb_Sample_std<<endl;

Int_t Chi2Min=0;
Int_t Chi2Max=10.;
Int_t NBinChi2=2000;
TH1F* Hist_Chi2=new TH1F(“Hist_Chi2”,"",NBinChi2,Chi2Min,Chi2Max);

TWaveForm* W_F_STD=new TWaveForm(Nb_Sample_std,t_Origine,T_samplingUp,astdwaveform.SampleW_F,"wave_form_ref");

TGraph* Graph_STD=W_F_STD->Graph();
TCanvas* c1 = new TCanvas(“c1”,“Control”,50,10,600,600);
c1->cd();
c1->Print(“c1.svg”);
Graph_STD->Draw(“AL*”);
Graph_STD->SetMarkerColor(2);
Graph_STD->SetLineColor(2);

Double_t* pm1;

TWaveForm** wf0=new TWaveForm*[nentries]; 

Double_t PiedEstal=172.;

TWaveForm* wf_trifouillage;
TWaveForm* wf_oversampled;
for (Int_t i = 0 ; i < nentries ;i++){
	pm1=new Double_t[N_sample];
	tree_wave_form->GetEntry(i);
	Tree_Energy_Time->GetEntry(i);
	
	for (Int_t j = 0 ; j < N_sample ; j++){		
		pm1[j]=asample2.SampleValue[j];				
	}	
	
	//Int_t Origine_des_temps=Tim/T_sampling+0.5; /// Arrondi et non troncature !
	
	//wf0[i]=new TWaveForm(N_sample,-Origine_des_temps*T_sampling,T_sampling,pm1,"wave_form");
	wf0[i]=new TWaveForm(N_sample,0.,T_sampling,pm1,"wave_form");
	(*wf0[i])-=PiedEstal;			/// soustraction du piedestal
	(*wf0[i])/=Q;                 /// normalisation en charge
	wf_oversampled=wf0[i]->UpSample(5);
	Int_t Origine_des_temps=Tim/T_samplingUp+0.5; /// Arrondi et non troncature !
	wf_oversampled->Set_t0(-Origine_des_temps*T_samplingUp);
	
	
	wf_trifouillage=new TWaveForm((*wf_oversampled));
	/*if (i%1000==0){
		wf_trifouillage->Draw("LPsame");
		c1->Update();
	}*/
	(*wf_trifouillage)-=(*W_F_STD); /// Difference point par point 
									/// entre le i eme evenement et la waveform de ref std
	Chi2=wf_trifouillage->chi_square(); /// Retourne la moyenne de la diff quad, le Chi2 quoi !
	
	Tree_Chi2->Fill();
	
	Hist_Chi2->Fill(Chi2);
	
	
	
	
	
}

Int_t EMin=0;
Int_t EMax=2000;
Int_t NBinE=2000;	
TH1F* EnergieDeposee=new TH1F("EnergieDeposee","",NBinE,EMin,EMax);	
TH1F* EnergieDeposeeCut=new TH1F("EnergieDeposeeCut","",NBinE,EMin,EMax);	

TH2F* Chi2_vs_Energy=new TH2F("Chi2_vs_Energy","",NBinChi2,Chi2Min,Chi2Max,NBinE,EMin,EMax);	


TCanvas* c2 = new TCanvas("c2","Chi2",50,10,600,600); 
c2->cd();
Hist_Chi2->Draw();
c2->Print("c2.svg");
for (Int_t i = 0 ; i < nentries; i++){
	Tree_Chi2->GetEntry(i);
	Tree_Energy_Time->GetEntry(i);
	if (Nrj>1600 && Nrj<1700){
		EnergieDeposeeCut->Fill(Nrj);
		Chi2_vs_Energy->Fill(Chi2/1.e17,Nrj);
		
	}
	EnergieDeposee->Fill(Nrj);
	//Chi2_vs_Energy->Fill(Chi2/1.e17,Nrj);
	
}

TCanvas* c3 = new TCanvas("c3","Nrj",50,10,600,600); 
EnergieDeposee->Draw();
EnergieDeposee->SetLineColor(2);
EnergieDeposeeCut->Draw("same");
EnergieDeposeeCut->SetLineColor(4);
c3->Print("c3.svg");
TCanvas* c4 = new TCanvas("c4","Chi2_Nrj",50,10,600,600);
//c4->SetLogz(1);
gStyle->SetPalette(1);
Chi2_vs_Energy->Draw("colz");

Double_t E1=EnergieDeposee->Integral();
Double_t E2=EnergieDeposeeCut->Integral();
cout<<"E1 "<<E1<<" E2 "<<E2<<endl;
c4->Print("c4.svg");

delete EnergieDeposee;
delete EnergieDeposeeCut;
delete Chi2_vs_Energy;

Chi2_File->Write();
Chi2_File->Close();

}

Thanks a lot

Cheers,

Loïc

Hi,

well, that doesn’t make much sense. Either you didn’t post the error message that the compiler cannot find TWaveForm.hh, or TWaveForm.hh doesn’t contain a type TWaveForm. Can you post all files as tgz archive so I can reproduce the issue? Either way it looks more like a problem that’s not at all connected to / caused by ROOT…

Cheers, Axel.

Hi,

what you sent works just fine for me:
g++ root-config --cflags root-config --libs shapeanalysis.cpp waveform.so -o shapeanalysis.exe

Cheers, Axel.

Hi,

It’s working well for me too !

Thanks a lot

Cheers,

Loïc