Installing root on windows 10,64bit for visual studio 2019

Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22.06
Platform: Windows 10
Compiler: Visual studio 2019

I started a physics course at university and they required to use root libraries for compiling programs.
Is there a way to use root libraries with Visual Studio 2019?
i tried to install the last release from the site,the 6.22.06, but when i try to include a library in vs it doesnt work,it show an error;
a friend told me it is because root for windows is only for 32bit computers,and mine is 64.
To install root i downloaded the .zip file from the site and then placed it to C:\ ,and then from the vs prompt i run c:\root\bin\thisroot.bat as the installation tutorial says in the release page,but then when i try to include libraries it doesnt work as i said before.
Can anybody tell me what i am doing wrong?you would save my life,thanks :slight_smile:

Yes, ROOT is 32 bit only, but works perfectly well on 64 bit computers. But if you want to create your own application, you need to make sure to create a 32 bit application and use the same compiler flags than ROOT itself. I would advise to use CMake to generate the solution file for VS 2019

i downloaded cmake but i cant understand how to use it on visual studio.

You have to create a CMakeLists.txt containing the information to generate the solution file. For example:

# Check if cmake has the required version

set(PROJECT_NAME YourProjectName)

find_package(ROOT REQUIRED)


include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})



# if dictionary is needed:

add_executable(${PROJECT_NAME} ${SOURCES} YourDictionary.cxx)
target_compile_options(${PROJECT_NAME} PRIVATE /MD)
target_link_libraries(${PROJECT_NAME} ${ROOT_LIBRARIES} libCore libRIO libHist)

Place it where your source code is, then open a Visual Studio command prompt, create a build directory, and type

cmake -G "Visual Studio 16 2019" -A Win32 -Thost=x64 [location of CMakeLists.tst and your source files]

This will generate a solution file. You can the also build from the command line, still in the build directory:

cmake --build . ---config Release

so i have to write all the root libraries headers an sources on that file, and create the solution file.
but what does the solution file do?sorry i am a real rookie so i have no idea of what to do next :laughing:
i will try and let you know.
thank you for the help :slight_smile:

So you want to use the ROOT libraries but you don’t know how to create an application? Are you sure it’s what you want to do? Or do you want to simply use ROOT? What do you have to do exactly?

in the course i have been doing we started by programming very easy applications first, like writing a program to calculate standard deviation or such,then we started using classes and creating our own statistics classes(which was kinda easy using visual studio),and then we sent the .cpp file(i just did write the source and then run the debug to make sure everythin was running,i never used the prompt).
Then they asked us to write some programmes using root libraries to diplay things like histograms.

#include <iostream>
#include "TH1F.h" 

int main(int argc, char** argv)
    TH1F istogramma("istogramma", "istogramma", 10, -5., 5.);
    return 0;

but for me it was a problem cause i wasnt using a linux environment and when i try to run that program on vs it doesnt work(i understand vs doesnt have the root libraries on default so using #include doesnt work,so i tried to install root to get the .h files and copy/paste them to the .h folder section of vs but that obviously didnt work), so my problem is how to use root libraries on vs for tings like that :laughing:.
sorry i am a real newbie so i imagine i might be annoying you,so thank you so much for being so comprehensive :smiley:

OK, so let’s try to make it simple:

  • open a x86 Native Tools Command Prompt for VS2019
  • run c:\root\bin\thisroot.bat
  • go to the directory where your cpp file is located and type:
    cl -nologo -Z7 -MD -GR -EHsc yourfile.cpp -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libHist.lib

it will generate an executable in the same directory

P.S. you can also add the c:\root\lib directory as additional library dir and c:\root\include as additional include dir in Visual Studio, and add the ROOT libraries (e.g. at least libCore.lib and libHist.lib) to be linked with your project

i tried,it does create an .exe file but it cant be run cause an error message pops up saying “lihist.dll and libcore.ddl has not been found”


i am gonna try this one,thank you :slight_smile:

You have to call c:\root\bin\thisroot.bat before running the executable.
If you want to be able to double-click on it from the File Explorer, then you have to create a new environment variable called ROOTSYS, pointing to c:\root and add %ROOTSYS%\bin to your PATH environment variable

including the libraries and include files did work,so visual studio doesnt show the root classes as errors anymore,but another problem did show up when i clicked the debug button:

i dont know what to do with this error,when i click on it that’s what shows up :

is it because i made something wrong adding new libaries and include dirs on visual studio?
is there a way to solve it?
sorry again to annoy you,and thank you so much in advance.

Since it works on the command prompt, I guess this is a due to a wrong configuration (compiler flag). So my question is: why don’t you use the command prompt (which is simpler)? Otherwise we can spend quite some time here… Anyway, can you try to build in Release mode to see if that change anything?

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