How to run c/c++ files on root

Hi @esh187,
you can run C++ code with ROOT with root -q functionname.cpp (ROOT will execute the function called functionname in file functionname.cpp). You can also open a ROOT prompt with root, and then load the contents of a program with .L myprogram.cpp, at which point you can just call any function that was defined in that file as normal.

For more complex usecases, my personal recommendation would actually be to use ROOT as any other C++ library and compile your programs with g++ -o program program.cpp $(root-config --libs --cflags) (you can check what root-config --libs --cflags does by running it in your prompt: it’s just a handy utility to provide all the compilation flags needed to compile a program that depends on ROOT).

Cheers,
Enrico

2 Likes