Home | News | Documentation | Download

Root Libraries on Visual studio

Dear Rooters,
I am currently studying physics at UniTO and i was asked to use root libraries in order to perform some data analysis.
I have alredy read Every single post about this topic on this forum yet coudd not manage to get root working on Vs.
I have alredy installed root and added the \include (c+±general) and \lib (linker-general) in the project properties.

My code is the following

#include <TROOT.h>
#include <TCanvas.h>
using namespace std;
int main()
{
	TCanvas* canv = new TCanvas("c1", "", 200, 10, 1280, 720);
	system("pause");
	return 0;
}

And this are the errors i get.

1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\ROOT\RWrap_libcpp_string_view.h(423,22): error C2589: ‘(’: illegal token on right side of ‘::’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\ROOT\libcpp_string_view.h(193,9): warning C4068: unknown pragma
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(537,1): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(537,1): message : This diagnostic occurred in the compiler generated function ‘std::enable_if<ROOT::TypeTraits::IsSignedNumeral::value,TString>::type operator +(T,const TString &)’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(547,1): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(547,1): message : This diagnostic occurred in the compiler generated function ‘std::enable_if<ROOT::TypeTraits::IsUnsignedNumeral::value,TString>::type operator +(T,const TString &)’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(557,1): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(557,1): message : This diagnostic occurred in the compiler generated function ‘std::enable_if<IsFloatNumeral::value,TString>::type operator +(T,const TString &)’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(560,54): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(572,40): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(611,60): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(620,52): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(635,44): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(645,49): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(657,47): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(678,49): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(691,68): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(694,68): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TString.h(697,69): warning C4267: ‘argument’: conversion from ‘size_t’ to ‘Ssiz_t’, possible loss of data
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TInterpreter.h(345,1): warning C4311: ‘type cast’: pointer truncation from ‘void *’ to ‘Long_t’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TInterpreter.h(345,1): warning C4302: ‘type cast’: truncation from ‘void *’ to ‘Long_t’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TVirtualQConnection.h(36,33): warning C4311: ‘type cast’: pointer truncation from ‘const void *’ to ‘Long_t’
1>D:\Programmazione\Nuova cartella\root_v6.18.04\include\TVirtualQConnection.h(36,33): warning C4302: ‘type cast’: truncation from ‘const void *’ to ‘Long_t’
1>Done building project “AnalisiDati.vcxproj” – FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Any suggestion?
Thanks a lot.

ROOT Version: root_v6.18.04
Platform: Visual Studio 2019

Hi,

First, ROOT is 32 bit only (i.e. you cannot create a win64 application). Then, I would advise to start with C++ macros you run with ROOT, instead of creating your own application. For example, your code cannot work. an instance of TApplication and a call to TApplication::Run() is needed for handling ROOT events, and don’t use system("pause")
You can also take a look at the examples in the test directory

Cheers, Bertrand.

Thanks for your reply,
can you explain me how to use root libraries in any visual studio enviroment?
Thanks.

Well, you have to include the proper headers and link against the root libraries, like in any C++ project using external libraries. Are you familiar with C++ and Visual Studio?

I am afraid I can’t say that i’m familiar with c++ and vs.
Yet it is very important for me to get all of this working and I will follow your instructions.
Here is what i have done so far:
-Dowloaded and installed (here “D:\Programmazione\Nuova cartella\root_v6.18.04”) the binary distribution Windows Visual Studio 2019.exe (not dbg)
-Opened a previuosly empty project of vs
-Added a new properti page and added in C++ -general-additional include directories D:\Programmazione\Nuova cartella\root_v6.18.04\include;%(AdditionalIncludeDirectories)
and in linker - general - additional library directories D:\Programmazione\Nuova cartella\root_v6.18.04\lib;%(AdditionalLibraryDirectories)

OK, so now, as I said, you have to write your code, include the proper headers and link against the root libraries

Hello, I’m sorry to disturb you. I did all the above things, but there are still errors after running.

Can you try to compile your code in the x86 Native Tools Command Prompt for VS 2019:

cl -nologo -Z7 -MD -GR -EHsc ConsoleApplication1.cpp -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGui.lib libGpad.lib libHist.lib

Thank you very much for your reply. The program can execute successfully when using the Command Prompt for VS 2019,but why?:sweat:

Check the compilation flags

Thanks! I modified the properties of ConsoleApplication1 according to the compilation flags, but it still can’t run. Is there any problem?

Well, there is most probably an incompatible flag in your long list of flags… I will need time to analyse which one(s) can cause the issue

Thank you very much for your help!:blush:

cl ConsoleApplication1.cpp -I E:\Tools\root_v6.18.04\include /link -LIBPATH:E:\Tools\root_v6.18.04\lib libCore.lib libGui.lib libGpad.lib libHist.lib

I’ve just tried. The above code can also work normally. I guess the problem may be in the .lib file.

remove the /permissive- flag

Succeed! Thank you so much! This problem has been bothering me for three days!:tada:

1 Like