# Lots of errors when running my root program

**URL:** <https://root-forum.cern.ch/t/lots-of-errors-when-running-my-root-program/37344>\
**Category:** Newbie\
**Created:** [December 28, 2019, 4:50am UTC](https://root-forum.cern.ch/t/lots-of-errors-when-running-my-root-program/37344 "2019-12-28T04:50:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![asp211](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/cdc98d/32.png) [@asp211](https://root-forum.cern.ch/u/asp211)\
**Post date:** [December 28, 2019, 4:50am UTC](https://root-forum.cern.ch/t/lots-of-errors-when-running-my-root-program/37344/1 "2019-12-28T04:50:39Z")

</div>

* * *

_ROOT Version:_ 6.18/04  
_Platform:_ VSCode  
_Compiler:_ VSCode  
_System:_ Mac OSX

* * *

I am a beginner to ROOT and after downloading it on my Mac and running the following macro:

```auto
#include <iostream>
#include <cmath>
using namespace std;

void f1(){

    c1 = new TCanvas("c1", "My RoOt Plots", 1500, 500);
    c1 -> Divide(3,1);

    c1 -> cd(1);
    f = new TF1("f", "sin(x)", 0, 5);
    f -> SetLineColor(kBlue + 3);
    f -> SetTitle("MyFunction; xval; yval");
    f -> Draw();

    c1 -> cd(2);
    g = new TF1("g", "cos(x)", 0, 5);
    g -> SetLineColor(kMagenta);
    g -> SetTitle("2ndFunction; xval2; yval");
    g -> Draw();

    c1 -> cd(3);
    h = new TF2("h", "x^2 + y^2", 0, 5, 0, 5);
    h -> SetLineColor(kPink);
    h -> SetTitle("OtherFunction; x; y");
    h -> Draw("surf1");

    

    cout << "\n";
}

```

When I run the command .x f1.C in the Mac terminal, it gives the following errors:

**/Users/myname/Documents/root2/macros/f1.C:7:5:**  **error:**  **use of undeclared identifier 'c1’**

c1 = new TCanvas(“c1”, “My RoOt Plots”, 1500, 500);

**^**

**/Users/myname/Documents/root2/macros/f1.C:8:5:**  **error:**  **use of undeclared identifier 'c1’**

c1 -\> Divide(3,1);

**^**

**/Users/myname/Documents/root2/macros/f1.C:10:5:**  **error:**  **use of undeclared identifier 'c1’**

c1 -\> cd(1);

**^**

Furthermore, the top two lines are underlined in red because I need to update my include path and that I cannot open the source file for either. How do I fix this?

Also, what lines should I have out in my .bash profile to make this work?

---

<div class="post-metadata">

**Author:** ![meu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/meu/32/20557_2.png) [@meu](https://root-forum.cern.ch/u/meu)\
**Post date:** [December 28, 2019, 5:14am UTC](https://root-forum.cern.ch/t/lots-of-errors-when-running-my-root-program/37344/2 "2019-12-28T05:14:48Z")

</div>

Hi, asp211

In your root macro, c1, f, g and h is constructor.

```auto
c1= new TCanvas(~);
f=new TF1(~);

```

This writhing is insufficient. It isn’t defined.  
You should define as follows.

```auto
TCanvas *c1=new TCanvas(~);
TF1 *f=new TF1(~);

```

Thia is correct writing.

I modified your code as fallows.

```auto
using namespace std;
void f1(){
  TCanvas *c1 = new TCanvas("c1", "My RoOt Plots", 1500, 500);
  c1 -> Divide(3,1);

  c1 -> cd(1);
  TF1 *f = new TF1("f", "sin(x)", 0, 5);
  f -> SetLineColor(kBlue + 3);
  f -> SetTitle("MyFunction; xval; yval");
  f -> Draw();

  c1 -> cd(2);
  TF1 *g = new TF1("g", "cos(x)", 0, 5);
  g -> SetLineColor(kMagenta);
  g -> SetTitle("2ndFunction; xval2; yval");
  g -> Draw();

  c1 -> cd(3);
  TF2 *h = new TF2("h", "x^2 + y^2", 0, 5, 0, 5);
  h -> SetLineColor(kPink);
  h -> SetTitle("OtherFunction; x; y");
  h -> Draw("surf1");

  c1->cd(0);

  cout << "\n";
}

```

Maybe, you can run by typing “root f1.cc” in command line.
