# Confusing error

**URL:** <https://root-forum.cern.ch/t/confusing-error/39843>\
**Category:** Newbie\
**Created:** [June 9, 2020, 9:32am UTC](https://root-forum.cern.ch/t/confusing-error/39843 "2020-06-09T09:32:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [June 9, 2020, 9:32am UTC](https://root-forum.cern.ch/t/confusing-error/39843/1 "2020-06-09T09:32:16Z")

</div>

I tried running this program again  
by .x SampleAveragingCode01.C++

```auto
void SampleAveragingCode01()
{
 static Int_t nf = 10;
 auto can = new TCanvas("c1", "c1", 800,500);
 gStyle->SetOptStat(0);
 auto hh = new TH1F("hh", "Averaging functions", 100,0,10);
 can->Draw();
 hh->Draw();

 TF1 * fp[nf];
 TString fn;
 for (Int_t i=0; i<nf; i++)
 {
  fn = "f"; fn += i;
  fp[i] = new TF1(fn, "[0]*x - [1]*x*x", 0, 10);
  fp[i]->SetParameters(60, 4 + gRandom->Gaus(1,0.3));
  fp[i]->SetLineColor(i+2);
  fp[i]->SetLineWidth(1);
  fp[i]->Draw("same");
 }

 Int_t npoints=100;
 Double_t x,y, dy = 10./npoints;
 auto avg = new TGraph(npoints);
 for (Int_t ip=0; ip < npoints; ip++) 
 {
  x = dy*ip + 0.5*dy;
  avg->SetPoint(ip, x, 0.);
 }

 for (Int_t i=0; i<nf; i++)
 {
  for (Int_t ip=0; ip < npoints; ip++)
  {
   avg->GetPoint(ip, x,y);
   avg->SetPoint(ip, x, y + fp[i]->Eval(x)/(Double_t)nf);
  }
 }

 avg->SetMarkerColor(1);
 avg->SetMarkerSize(1);
 avg->Draw("* same");
 hh->SetMaximum(300);
 can->Modified();
 can->Update();
}

```

but it gives error…

```auto
root [2] .x SampleAveragingCode01.C++
Info in <TUnixSystem::ACLiC>: creating shared library /home/jaybee/CodesScattering/./SampleAveragingCode01_C.so
In file included from /home/jaybee/CodesScattering/SampleAveragingCode01_C_ACLiC_dict.h:34:0,
                 from /home/jaybee/CodesScattering/SampleAveragingCode01_C_ACLiC_dict.cxx:17:
/home/jaybee/CodesScattering/./SampleAveragingCode01.C: In function ‘void SampleAveragingCode01()’:
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:4:7: error: ‘can’ does not name a type
  auto can = new TCanvas("c1", "c1", 800,500);
       ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:5:2: error: ‘gStyle’ was not declared in this scope
  gStyle->SetOptStat(0);
  ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:6:7: error: ‘hh’ does not name a type
  auto hh = new TH1F("hh", "Averaging functions", 100,0,10);
       ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:7:2: error: ‘can’ was not declared in this scope
  can->Draw();
  ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:8:2: error: ‘hh’ was not declared in this scope
  hh->Draw();
  ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:10:2: error: ‘TF1’ was not declared in this scope
  TF1 * fp[nf];
  ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:10:8: error: ‘fp’ was not declared in this scope
  TF1 * fp[nf];
        ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:11:10: error: aggregate ‘TString fn’ has incomplete type and cannot be defined
  TString fn;
          ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:15:15: error: expected type-specifier before ‘TF1’
   fp[i] = new TF1(fn, "[0]*x - [1]*x*x", 0, 10);
               ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:16:32: error: ‘gRandom’ was not declared in this scope
   fp[i]->SetParameters(60, 4 + gRandom->Gaus(1,0.3));
                                ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:24:7: error: ‘avg’ does not name a type
  auto avg = new TGraph(npoints);
       ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:28:3: error: ‘avg’ was not declared in this scope
   avg->SetPoint(ip, x, 0.);
   ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:35:4: error: ‘avg’ was not declared in this scope
    avg->GetPoint(ip, x,y);
    ^
/home/jaybee/CodesScattering/./SampleAveragingCode01.C:40:2: error: ‘avg’ was not declared in this scope
  avg->SetMarkerColor(1);
  ^
g++: error: /home/jaybee/CodesScattering/SampleAveragingCode01_C_ACLiC_dict.o: No such file or directory
Error in <ACLiC>: Compilation failed!
Error: Function SampleAveragingCode01() is not defined in current scope :0:
***Interpreter error recovered***
root [3] 

```

what could have been wrong?

regards,  
jaybee

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [June 9, 2020, 9:35am UTC](https://root-forum.cern.ch/t/confusing-error/39843/2 "2020-06-09T09:35:57Z")

</div>

did it lose ROOT? I just got back with this computer…

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [June 9, 2020, 9:39am UTC](https://root-forum.cern.ch/t/confusing-error/39843/3 "2020-06-09T09:39:18Z")

</div>

Or is there something I could do to fix the problem without re-installing it? 🙂

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [June 9, 2020, 10:11am UTC](https://root-forum.cern.ch/t/confusing-error/39843/4 "2020-06-09T10:11:49Z")

</div>

Hi @jbmagallanes,

> [@jbmagallanes](#):
>
> .x SampleAveragingCode01.C++

You are compiling your script so you need to add the correct includes. See [the guide](https://root.cern.ch/root/htmldoc/guides/users-guide/ROOTUsersGuide.html#aclic-compiling-scripts-into-libraries)

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [June 10, 2020, 7:44am UTC](https://root-forum.cern.ch/t/confusing-error/39843/5 "2020-06-10T07:44:08Z")

</div>

They were there actually… but was not included in the code that I posted, sorry.  
All the “includes” were there.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 10, 2020, 7:46am UTC](https://root-forum.cern.ch/t/confusing-error/39843/6 "2020-06-10T07:46:45Z")

</div>

Which OS? Which version of ROOT? Which compiler?

---

<div class="post-metadata">

**Author:** ![jbmagallanes](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/jbmagallanes/32/20291_2.png) [@jbmagallanes](https://root-forum.cern.ch/u/jbmagallanes)\
**Post date:** [June 10, 2020, 8:29am UTC](https://root-forum.cern.ch/t/confusing-error/39843/7 "2020-06-10T08:29:02Z")

</div>

hi @vpadulan and @bellenot, I run it again today and it worked fine… it is okay now… anyway, gracias 🙂
