Home | News | Documentation | Download

Using Root in Windows Visual Studio 2019

Hello,

I started learning C++/Visual Studio about 3 weeks ago and Root yesterday, so please assume I have no idea about anything.

My problem in a short summary:
How do I connect root to an existing C++ Code in Windows Visual Studio 2019, so I can use root commands in it?

More Details:
In the context of my Master Thesis I got a Data Acquisition Card (TimeTagger4-2G by Cronologic) for my Multichannel Plate. Unfortunately it was quite cheap, because it came without a ready to use software. Only a C++ example program, some .dll, some .lib and the Windows specific drivers (hence why I use windows visual studio) were included. The example program I managed to build, run and it does what it is supposed to do. Since I need to make histograms out of my data someone suggested I use root for this. I started learning root yesterday.
So how can I include the root commands in the already existing C++ example Code?

  • using Windows Visual Studio 2019
  • OS: Windows 10 64bit
  • root version: root_v6.18.04

What I do understand so far:

#inlcude <TH1.h>

What I tried so far:
I installed root by downloading the Pro .exe file from here: [https://root.cern.ch/downloading-root] and double clicking on it, when the download was complete. I connected the bin folder with all the .dll to my visual studio project and also the lib folder with all the .lib. I also copy pasted the content of the include folder into the same folder as my visual studio project. The only thing I changed in the code itself was to add in the beginning the command

#include "TH1.h" 

So far I get build errors. I assume I do something fundamentally wrong, but I can’t find a solution by Google or reading the user guide, because everything I find assumes a higher level of competence from the reader than I have, especially regarding windows visual studio.

I think @bellenot can help you.

Hi,

This is not needed, you simply have to add the include directory to the list of include directories in Visual Studio.

What kind of errors?

I get a lot of errors and warnings (around 100) after adding the single line for the TH1 header into the code. I guess they are all caused by linking stuff wrong? I’ll give one example for every type of error and warning I get.

  • Warning:C4267 'argument': conversion from 'size_t' to 'Ssiz_t', possible loss of data C:\Users\Administrator\Documents\TimeTagger4 software developement\test5\test5\TString.h Line:648

  • Warning:LNK4248 unresolved typeref token (01000016) for 'TClass'; image may not run test5 C:\Users\Administrator\Documents\TimeTagger4 software developement\test5\test5\Source.obj Line:1

  • Warning:LNK4272 library machine type 'x86' conflicts with target machine type 'x64' C:\Program Files (x86)\root_v6.18.04\lib\libHist.lib Line:1
    (comment from me about this warning: As I understand it, I have to run it as type ‘x64’, because the code of the data acquisition card seem to have a problem otherwise and doesn’t build)

  • Error:LNK2028 unresolved token (0A000588) "public: __cdecl TVersionCheck::TVersionCheck(int)" (??0TVersionCheck@@$$FQEAA@H@Z) referenced in function "void __clrcallanonymous namespace’::dynamic initializer for 'void __clrcall gVersionCheck::A0x13e4cadf(void)''(void)" (???__E?A0x13e4cadf@gVersionCheck@@YMXXZ@?A0x13e4cadf@@$$FYMXXZ) C:\Users\Administrator\Documents\TimeTagger4 software developement\test5\test5\Source.obj Line:1

  • Error:LNK2001 unresolved external symbol "protected: virtual void __cdecl TObject::DoError(int,char const *,char const *,char *)const " (?DoError@TObject@@MEBAXHPEBD0PEAD@Z) C:\Users\Administrator\Documents\TimeTagger4 software developement\test5\test5\Source.obj Line:1

  • Error:LNK2019 unresolved external symbol "public: static bool __cdecl TObject::GetObjectStat(void)" (?GetObjectStat@TObject@@$$FSA_NXZ) referenced in function "public: __cdecl TObject::TObject(class TObject const &)" (??0TObject@@$$FQEAA@AEBV0@@Z) C:\Users\Administrator\Documents\TimeTagger4 software developement\test5\test5\Source.obj Line:1

  • Error:LNK1120 72 unresolved externals C:\Users\Administrator\Documents\TimeTagger4 software developement\test5\test5\x64\Debug\test5.exe Line:1

Edit: I played around a bit and googled some more. Could it be that root does not work with x64 systems and my data acquisition card works only with x64 bit, so they are incompatible by default? :confounded:

So some of the warnings are harmless, but Root is only available in 32 bit for the time being on Windows

That explains a lot. Thank you very much for your help. Guess I’m back to square one and have to find another option.

Well, you have several options. You can use a socket to communicate with ROOT, or you can simply save your data in a file and read it back with ROOT…