TFitResultPtr does not return any data although it is there

Hello, I am having some problems using TFitResultPtr in a compiled c++ program on Windows (and Visual Studio) using Root 5.34.34 .

#include “TGraph.h”
#include “TGraphErrors.h”
#include “TFile.h”
#include “TF1.h”
#include “TFitResult.h”
#include “Fit\FitResult.h”
#include “TFitResultPtr.h”
#include “TError.h”

int main(){
	TGraphErrors * g = new TGraphErrors("input.txt", "%lg %lg %lg"); //same problem happens if g is TGraph or TH1F
	string formula;
	formula = "pol1";
	TF1 * f = new TF1("f", formula.c_str() );
	TFitResultPtr  res= g->Fit(f, "S"); 
	bool c=res->IsEmpty(); //returns true

As you can see reading the comments, res->IsEmpty() returns true, the fields are not properly filled.

Using Visual Studio debugger I managed to take a look at the pointed object itself, and it turns out it has some memory of the correct data.

In the attached image you can see an analysis of res. The correct data is there (indicated by my arrow “What I want to get” in the image), I checked the details inside the variable and they are exactly those I expect knowing the input data, yet when I actually access the data in code I only get incorrect results (the ones indicated by my arrow “What I actually get”). What am I doing wrong? How can I fix this?
input.txt (430 Bytes)


Here is what I get with ROOT 5.34/37, Visual Studio 2012. First the console output:

And then the debug session:

So could you tell me how you compile your example, with which version of Visual Studio, and which version of ROOT (from binary, from source, debug/release)

Cheers, Bertrand.

Hello Bertrand, thank you for your help. I mainly use VS Community 2015, but since it is not officially supported by ROOT, I also tried my code with VS Express 2013 for Windows Desktop and VS Express 2012 for Windows Desktop, obtaining similar results.

I installed ROOT 5.34.34 debug version for VS 2013 via the exe file called root_v5.34.34.win32.vc12.debug.exe. I would also like to point out that the download page uses VS version name instead of year which can be a bit confusing.

Here you can find the entire command line options used in VS 2013 compiler

and linker

If you want to try this on VS 2012 I think it’s enough to replace “vc.120.pdb” with “vc.110.pdb”.


So here is a general rule for building C++ code on Windows with Visual Studio:

  • The version of Visual Studio used to build your application must be the exact same version than the one used to build ROOT
  • If you use the debug version of ROOT, you have to build your code in debug mode (one cannot mix debug/release code)
  • if possible, use the same compilation flags (you can take a look at $(ROOTSYS)/include/compiledata.h)

For example, here is how I built you example code (on the command prompt):

cl -nologo -Z7 -MD -GR -EHsc goldrunout.cxx -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libHist.lib libRIO.lib
I’ll try with 5.34.34 and I’ll let you know…

[color=#FF0000]EDIT[/color]: So I just tried with 5.34.34 and it works just fine…

Cheers, Bertrand.

Hello again Bertrand, thank you for giving me your command line options; thanks to those I managed to pinpoint the problem. However, I am now on a different machine (which has the same setup though), therefore I will have to reproduce the solution I found on first computer before considering this situation resolved.

I managed to solve my problem by changing some compiler options. In particular the Visual Studio default debug configuration adds the preprocessor definition “_DEBUG” and enables multithreaded debug dll, I changed those to “NDEBUG” and multithreaded dll and that solved my problems. In other words I changed


Tomorrow I will try this on my primary machine. Again thank you for your help.

I have tested this on my primary machine and it works. This question can be tagged as SOLVED.

However it is interesting that the Debug version of root has a problem that can be solved by using options that shouldn’t be used in a debug configuration such as