Using ROOT in a c++ code

Hi, I’m coding as a project a c++ simulation of ALICE experiment. I need to use the various ROOT classes and features in my code: but I don’t know
-1) What should I include (and where: only in my main? or every where I use ROOT’s features) in my code (I mean #include “etcetc”)
-2) How should i compile the code

I have 3 .cpp files and their relative .hpp, and the main.cpp.
Until now I compiled like this: g++ file1.cpp file2.cpp file3.cpp main.cpp

And I should say I’m not able to compile using CMake, but I would like to learn how to, so if anyone knows some good guide/tutorial it would be very kind if you reccomended it. Thanks

I will use the basic tools of ROOT, but for the #include just go safe, it’s better if there are more than needed than less. (I will try which one are really necessary in a second moment)
For example i need to use random generator, histograms and 1d functions.

Thanks for the help!

_ROOT Version: Updated in November 2021
_Platform: Ubuntu
_Compiler: g++

$(root-config --cxx --cflags) file1.cpp file2.cpp file3.cpp main.cpp $(root-config --libs)

Thanks, that seem to work. I found some indication of the professor, but I encounter various error. I’ll post them here so maybe you could tell me if the commands seem right to you

  1. .L file1.cpp+
    .L file2.cpp+
    .L file3.cpp+

  2. write, in the main.cpp, R__LOAD_LIBRARY( after including the headers of file1, file2, and file3 (they contain a class each).

  3. .L main.cpp+

concerning your cmake question, have a look at this

Not completely sure what you want to accomplish here.
Please have a look at this and scroll
down to the section " Compile a Macro with the Compiler"

In part 1, you are creating three libraries, one for each .cpp file.
In part 2, you want to load these libraries but that has actually already
happened in part 1.
In part 3 you do this with the main program, all dependencies on ROOT libraries
and you functions should have been resolved. You follow this by executing
the function “main”.

What did not work for you ?