Win7 with mingw and root


I am under windows 7, using g++ (4.5.2) with mingw and I am trying to compile and link a simple code using ROOT classes (creating a TH1F) to test it. I am using ROOT 5.30/01 the binaries of which I installed using the VC++ 9 MSI installer.

I have set the PATH and LD_LIBRARY_PATH environment variables to point to the bin and lib directories of ROOT. The code compiles but it has some problem during linking:

this is OK

g++ -I/c/root/include -c test.cpp

this is not OK

g++ -o test -L/c/root/bin -L/c/root/lib -lGpad -lHist -lGraf -lGraf3d -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lRIO -lNet -lThread -lCore -lCint -lm test.o

test.o:test.cpp:(.text+0x60): undefined reference to TH1F::TH1F(char const*, char const*, int, double, double)' test.o:test.cpp:(.text+0xb9): undefined reference toTObject::operator delete(void*)'
test.o:test.cpp:(.text+0x118): undefined reference to TVersionCheck::TVersionCheck(int)' test.o:test.cpp:(.text$_ZN7TObjectnwEj[TObject::operator new(unsigned int)]+0xd): undefined reference toTStorage::ObjectAlloc(unsigned int)'
collect2: ld returned 1 exit status

The code was this (it compiles fine without the ROOT stuff):

#include <iostream>
#include <TH1F.h>
#include <TSystem.h>
#include <TROOT.h>

using namespace std;

int main( int argc, char** argv )
  TH1F * h = new TH1F("h1", "h1",100, 0, 100); 
  delete h;

  cout << "Hello World" << endl;
  return 0;

Perhaps I forgot some lines? Or other step? Under linux I usually have some custom classes as well and there I need to generate and compile a dictionary for those classes and that works OK. But when trying the same exercise (creating class with ClassDef/ClassImp lines, generating dictionary with rootcint, compiling and linking all of them) I get similar undefined reference error from the linker.

Thanks for any help,

Hi Balint,

The Windows binaries have to be used with MSVC++ compiler/linker, not with gcc/g++

Cheers, Bertrand.

Hi Bertrand,

thanks for your answer.

I remember in the past it was possible to compile ROOT-based code with mingw + gcc/g++. Perhaps
the cygwin tar was it and not the MSVC binaries. But I see the cygwin tar is an “unsupported toy”. If I can’t get along with that one either I will just go for MSVC (I wanted to avoid that).


Well, if MINGW allows to build regular MSVC++ libraries with g++, then it should work (I never tried, and not going to :wink:). The Windows binaries we provide are built with MSVC (7.1, 9.0 and 10.0). The cygwin ones are built with gcc4.3 (if you want to try…)

Cheers, Bertrand.