How to include ROOT libraries in standard C/C++ programs?

Hi rooters!

I know how to write ROOT macros compilable with ACLiC inside the ROOT framework. Now my question is the following: can I write a standard C/C++ main() including ROOT components and then compile the code with gcc/g++?
I tried to write a simple C++ main() specifying the full path of some ROOT libraries (e.g. “/opt/root/include/TH1F.h” with ROOT installed in the /opt directory) but when I compile it with g++ the compilation fails and I get numerous errors!

Here’s my simple code:

#include <iostream>

#include "/opt/root/include/TH1F.h"
#include "/opt/root/include/TRandom3.h"
#include "/opt/root/include/TCanvas.h"

int main(int argc, char* argv[] ){

   std::cout << "This is a test" << std::endl;

   TH1F *histo = new TH1D("histo","MyHisto",100,0,1);
   TCanvas *cvs = new TCanvas();

   for(int i = 0; i < 10000; ++i)histo->Fill( gRandom->Rndm() );

   return 0;

Where am I wrong? Do I need a Makefile?
As a matter of fact, I started to work with the CMS collaboration and its huge CMSSW framework and I ‘discovered’ that the most part of the data analysis code uses the ROOT components but it’s compiled outside ROOT!
Hence I’d like to understand how to compile a standard C/C++ program including ROOT features.
Any answer or example would be appreciated!

Best regards!





I created a .so library, which calls root functions. I installed root on my Open Suse 12.2. built the .so library using c/C++ code.
Now Im trying to call the .so file from mono using c#.
But Im getting SIGILL error, i.e., when Im trying to do TH1F* hist =new TH1F(); in the C++ code.


See Using ROOT classes from C#

Cheers, Axel