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

**URL:** <https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616>\
**Category:** ROOT\
**Tags:** root\
**Created:** [December 6, 2020, 6:16pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616 "2020-12-06T18:16:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 6, 2020, 6:16pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/1 "2020-12-06T18:16:09Z")

</div>

* * *

_Please read [tips for efficient and successful posting](https://root-forum.cern.ch/t/tips-for-efficient-and-successful-posting/28292) and [posting code](https://root-forum.cern.ch/t/posting-code-read-this-first/28293)_

_ROOT Version:_ 6.22.06  
_Platform:_ Windows 10  
_Compiler:_ Visual studio 2019

* * *

HI,  
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 🙂

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 7, 2020, 7:10am UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/3 "2020-12-07T07:10:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 7, 2020, 1:08pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/4 "2020-12-07T13:08:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 7, 2020, 1:35pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/5 "2020-12-07T13:35:14Z")

</div>

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

```auto
# Check if cmake has the required version
CMAKE_MINIMUM_REQUIRED(VERSION 3.16.4 FATAL_ERROR)

set(PROJECT_NAME YourProjectName)
project(${PROJECT_NAME})

find_package(ROOT REQUIRED)

set(CMAKE_CXX_FLAGS "${ROOT_CXX_FLAGS}" )

include(${ROOT_USE_FILE})
include_directories(${ROOT_INCLUDE_DIRS} ${CMAKE_SOURCE_DIR})
link_directories(${ROOT_LIBRARY_DIR})

set(HEADERS
  YourFirstHeader.h
  YourSecondHeader.h
  YourThirdHeader.h
)

set(SOURCES
  YourFirstSource.cxx
  YourSecondSource.cxx
  YourThirdSource.cxx
)

# if dictionary is needed:
ROOT_GENERATE_DICTIONARY(YourDictionary.cxx ${HEADERS} LINKDEF YourLinkDef.h)

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

```auto
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:

```auto
cmake --build . ---config Release

```

---

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 7, 2020, 1:50pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/6 "2020-12-07T13:50:45Z")

</div>

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 😆  
i will try and let you know.  
thank you for the help 🙂

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 7, 2020, 1:54pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/7 "2020-12-07T13:54:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 7, 2020, 2:13pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/8 "2020-12-07T14:13:29Z")

</div>

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.

```auto
#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 😆.  
sorry i am a real newbie so i imagine i might be annoying you,so thank you so much for being so comprehensive 😃

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 7, 2020, 2:20pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/9 "2020-12-07T14:20:33Z")

</div>

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:

```auto
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

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 7, 2020, 2:28pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/10 "2020-12-07T14:28:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 7, 2020, 2:47pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/11 "2020-12-07T14:47:54Z")

</div>

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”

---

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 7, 2020, 2:48pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/12 "2020-12-07T14:48:28Z")

</div>

> Blockquote

> [@bellenot](#):
>
> 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 am gonna try this one,thank you 🙂

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 7, 2020, 2:52pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/13 "2020-12-07T14:52:31Z")

</div>

> [@Foxtroat](#):
>
> 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”

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

---

<div class="post-metadata">

**Author:** ![Foxtroat](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/foxtroat/32/24218_2.png) [@Foxtroat](https://root-forum.cern.ch/u/Foxtroat)\
**Post date:** [December 8, 2020, 4:58pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/14 "2020-12-08T16:58:27Z")

</div>

Hi,  
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:

 ![source](https://root-forum.cern.ch/uploads/default/original/3X/1/6/162b871cfe37777265baea13b595fec0488183e6.png)  
i dont know what to do with this error,when i click on it that’s what shows up :  
 ![error std](https://root-forum.cern.ch/uploads/default/original/3X/0/f/0fb3c70071eec92c7fa76ab9d3e5c7cfd413bf18.png)

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.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [December 8, 2020, 5:04pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/15 "2020-12-08T17:04:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [December 22, 2020, 5:10pm UTC](https://root-forum.cern.ch/t/installing-root-on-windows-10-64bit-for-visual-studio-2019/42616/16 "2020-12-22T17:10:24Z")

</div>

Closed on December 22, 2020, 5:10pm UTC

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