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:
Thank you. Indeed it has a main(), here’s my macro:
#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;
}
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:
root [0] .x factorial.C
ingresa un numero
3
El Factorial de 3 es: 6
root [1]
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.