How to compile multiple files in ROOT

wrongusername picture wrongusername · Oct 22, 2011 · Viewed 8k times · Source

I wrote a C++ program (with a main.cpp, and various header and implementation files) that compiles fine under g++. Now I am trying to compile it in Cern's ROOT library, but I do not know how to, since the only way I know how to compile files in ROOT is by using .L main.cpp.

How can I include multiple files in ROOT?

Answer

andybuckley picture andybuckley · Dec 12, 2011

The most reliable way to use ROOT (at least historically and currently) is to ignore the interpreter other than for the simplest explorations and explicitly compile your C++ programs against the ROOT libraries. For example, use

g++ MySource.cc `root-config --libs --cflags` -o foo

to compile an executable "foo" from a single source file. For more info on that helper script run "root-config --help".

Multi-file programs/libraries are nothing special provided that you supply the required args to point at the ROOT libraries and headers (and that the libs are available in LD_LIBRARY_PATH at runtime.) Standard C++ guides will explain that step if needed. You can safely put this into a makefile, too.

For my money this is both easier and more reliable than using the .L etc. commands in the CINT interpreter. Last time I tried, ACLiC was actually compiling against a temporary (and mangled) version of the specified source file, so any error messages from the compiler were pretty much useless!