file.C with gROOT cannot be compiled

Hi, ALL:
I am new in root, and I am learning it now.
I met a problem that whenever I compiled a file.C with gROOT in it, I failed.
For example, here is a simple code:

[code]#include “TH1F.h”
#include “TPad.h”

void DrawGauss()
{
TH1F* h=(TH1F*)gROOT->FindObject(“h_gaus”);
if(h){
h->Reset();
}else{
h=new TH1F(“h_gaus”,“Une gaussienne”,100,0.,100);
}
h->Draw();
for(Double_t x=0; x<100; x++){
Double_t f = 20.*exp(-pow(x-50.,2)/2./pow(10,2));
h->Fill(x,f);
gPad->Modified();
gPad->Update();
}
}[/code]
In my PC, it will end up with:

root [4] .L l1gauss.C+ Info in <TUnixSystem::ACLiC>: creating shared library /home/fengyich/CERN_Root/L_files/./l1gauss_C.so In file included from /home/fengyich/CERN_Root/L_files/l1gauss_C_ACLiC_dict.h:34:0, from /home/fengyich/CERN_Root/L_files/l1gauss_C_ACLiC_dict.cxx:17: /home/fengyich/CERN_Root/L_files/./l1gauss.C: In function ‘void DrawGauss()’: /home/fengyich/CERN_Root/L_files/./l1gauss.C:6:18: error: ‘gROOT’ was not declared in this scope TH1F* h=(TH1F*)(gROOT->FindObject("h_gaus")); ^ g++: error: /home/fengyich/CERN_Root/L_files/l1gauss_C_ACLiC_dict.o: No such file or directory Error in <ACLiC>: Compilation failed! root [5] .L l1gauss.C+ Info in <TUnixSystem::ACLiC>: creating shared library /home/fengyich/CERN_Root/L_files/./l1gauss_C.so In file included from /home/fengyich/CERN_Root/L_files/l1gauss_C_ACLiC_dict.h:34:0, from /home/fengyich/CERN_Root/L_files/l1gauss_C_ACLiC_dict.cxx:17: /home/fengyich/CERN_Root/L_files/./l1gauss.C: In function ‘void DrawGauss()’: /home/fengyich/CERN_Root/L_files/./l1gauss.C:6:18: error: ‘gROOT’ was not declared in this scope TH1F* h=(TH1F*)(gROOT->FindObject("h_gaus")); ^ g++: error: /home/fengyich/CERN_Root/L_files/l1gauss_C_ACLiC_dict.o: No such file or directory Error in <ACLiC>: Compilation failed!

I am puzzled now and need help!
Thank you!
BTW: the root version is 5.34/34

1 Like

#include “TROOT.h”