G++ with root libraries - dependencies


I have a fairly simple question about using ROOT with g++. This question has probably been answered elsewhere, but if so I have not found the right place to look.

It seem straightforward for me to use simple root classes in my .cc files. I just #include “TH1.F” or whatever in my .cc file, and when I compile I use:

“g++ blah.cc -I$ROOTSYS/include -L$ROOTSYS/lib …”

The challenge is knowing which shared object libraries I need. I have figured out a number of things through trial and error. For example, when using TCanvas I think I need “-lGpad”. But it can be very tedious sorting through all of the libraries and trying to figure out which one the linker needs whenever I compile code with a new root class. Can anyone suggest to me a website I can look at that explains how to do this, or a script I can run to view the dependencies for a given root class?



If you look at the reference guide at root.cern.ch/root/html/ClassIndex.html you will see that each class is associated with a modules and with a package within this module. The name of the module and the package are noted at the top of the documentation page for each page. For example TCanvas is in Gpad in the module Graf2d. The name of the library is the name of the package using title case.


Thanks Philippe!


it’s even easier, with less guesswork involved: the semi-transparent box on the top right tells you the #include file name and the library for every ROOT class. See e.g. root.cern.ch/root/html/TH1 which says “library: libHist”.

Cheers, Axel.