Compile ROOT projects with Visual Studio

I am using ROOT in Windows with Visual Studio. I built ROOT from source and it went fine. I can use macros with root.exe perfectly. But I need to use ROOT libraries with other things as well as be able to debug codes and I just can’t get ROOT parts to compile in Visual Studio. For example, this basic code:

#include <TApplication.h>
#include <TF1.h>
#include <TRandom3.h>
int main(int argc, char** argv)
	TApplication theApp("App", &argc, argv);
	TF1* f1 = new TF1("f1", "sin(x)/x" , 0, 10);
	return 0;

gives a compiler error:
‘__find_end’: is not a member of 'std` in file RWrap_libcpp_string_view.h in line 428.

What I tried:

  1. Added environment vars ROOTSYS and %ROOTSYS%\bin in Paths
  2. Solution properties–>Configuration properties–> Added the include and library dirs
  3. Solution properties–>Linker–>Input–> Added all the .lib files

it still shows the same error while compilation.

@bellenot can you help?

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.21
Platform: Windows
Compiler: cl

It is most probably due to incompatible compiler flags.Could you simply try, in a x86 Native Tools Command Prompt for VS 2019:

cl -nologo -O2 -MD -GR -EHsc -I%ROOTSYS%\include test.cpp /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGpad.lib libHist.lib /out:test.exe

(replace test.cpp with your file name)

Thanks. It at least compiles. But the program execution stalls and nothing happens.

It seems to be a problem with TApplication. Because without that, the program quits normally. I will use mainly use TMVA from ROOT so can you please tell me what should be a typical command/what other libs I should include?

What did you expect? You don’t do anything in your code…

TApplication is required to handle/process events. It you want to exit, simply call gApplication->Terminate(0);
And to use TMVA, you have to link against libTMVA.lib

Sorry I forgot about the Draw() command. It works perfectly now. Thanks a lot.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.