# Can't open macros with ROOT

**URL:** <https://root-forum.cern.ch/t/cant-open-macros-with-root/46429>\
**Category:** Newbie\
**Created:** [August 24, 2021, 10:28pm UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429 "2021-08-24T22:28:39Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leonardo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/e56c9b/32.png) [@Leonardo](https://root-forum.cern.ch/u/Leonardo)\
**Post date:** [August 24, 2021, 10:28pm UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/1 "2021-08-24T22:28:40Z")

</div>

Hi everyone

I just installed ROOT 6.24/02 for Mac OS BigSur v11.4. There are no error messages when I launch ROOT, but when I try to open any macro I receive the next error message:

Processing main.cpp…  
Error in TApplication::TApplication: only one instance of TApplication allowed

You know what could I do to open my macros?

Regards

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 25, 2021, 7:08am UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/2 "2021-08-25T07:08:38Z")

</div>

It seems your macro has a `main()` ? can you post a none working macro here ?

---

<div class="post-metadata">

**Author:** ![Leonardo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/e56c9b/32.png) [@Leonardo](https://root-forum.cern.ch/u/Leonardo)\
**Post date:** [August 25, 2021, 7:26am UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/3 "2021-08-25T07:26:27Z")

</div>

Thank you. Indeed it has a main(), here’s my macro:

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

int main(){
int i;
int fact=1;
int numero;

cout << "ingresa un numero"<<endl;
cin>>numero;

if (numero<0) {fact =0;}
else if (numero==0) {fact=1;}
else {
for (i = 1; i <= numero; i++){
fact = fact*i;
}
}
cout<<" El Factorial de "<< numero<< " es: " << fact << endl;

return 0;
}

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 25, 2021, 7:33am UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/4 "2021-08-25T07:33:15Z")

</div>

### factorial.C:

```auto
void factorial(){
   int i;
   int fact=1;
   int numero;

   cout << "ingresa un numero"<<endl;
   cin>>numero;

   if (numero<0) {fact =0;}
   else if (numero==0) {fact=1;}
   else {
      for (i = 1; i <= numero; i++){
         fact = fact*i;
      }
   }
   cout<<" El Factorial de "<< numero<< " es: " << fact << endl;
}

```

### Execution:

```auto
root [0] .x factorial.C
ingresa un numero
3
 El Factorial de 3 es: 6
root [1] 

```

---

<div class="post-metadata">

**Author:** ![eguiraud](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/eguiraud/32/32217_2.png) [@eguiraud](https://root-forum.cern.ch/u/eguiraud)\
**Post date:** [August 25, 2021, 8:10am UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/5 "2021-08-25T08:10:05Z")

</div>

Hi @Leonardo ,  
and welcome to the ROOT forum.  
To expand on Olivier’s answer: you can write ROOT programs as standard C++ programs (i.e. with a `main` function) and compile them as usual (e.g. with `g++ -o program program.cpp $(root-config --libs --cflags)`) **or** you can write what we usually call a “macro” or a script, in which case when you run it with `root macro.C` or, from the ROOT prompt, as `[0] .x macro.C`, ROOT executes the function in that file that has the same name as the file (i.e. it would try to execute the function `macro()` when you do `root macro.C`).

Executing a macro with a `main` function in it seems to confuse the ROOT C++ interpreter.

I hope this clarifies things a bit.

Cheers,  
Enrico

---

<div class="post-metadata">

**Author:** ![Leonardo](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/e56c9b/32.png) [@Leonardo](https://root-forum.cern.ch/u/Leonardo)\
**Post date:** [August 26, 2021, 12:08am UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/6 "2021-08-26T00:08:40Z")

</div>

Thank you Enrico, that helped a lot!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 26, 2021, 7:33am UTC](https://root-forum.cern.ch/t/cant-open-macros-with-root/46429/7 "2021-08-26T07:33:58Z")

</div>

[This chapter in the ROOT](https://root.cern/manual/interacting_with_shared_libraries/) Manual should cover this question.
