# On Visual Studio 2022 Root running problem

**URL:** <https://root-forum.cern.ch/t/on-visual-studio-2022-root-running-problem/53636>\
**Category:** Newbie\
**Tags:** root\
**Created:** [February 15, 2023, 4:49am UTC](https://root-forum.cern.ch/t/on-visual-studio-2022-root-running-problem/53636 "2023-02-15T04:49:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Billy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/billy/32/32482_2.png) [@Billy](https://root-forum.cern.ch/u/Billy)\
**Post date:** [February 15, 2023, 4:49am UTC](https://root-forum.cern.ch/t/on-visual-studio-2022-root-running-problem/53636/1 "2023-02-15T04:49:01Z")

</div>

\_ROOT Version: 6.28  
\_Platform: Windows10, 64bit  
\_Compiler: Visual studio 2022

It’s a very simple test code. I set the including path, library path, lib input, environment variables. The code is built succeeded. But can not run. I copy all the \*.dll files from bin folder to the built exe folder. It still can not run. Please help let me know where I’m wrong. Thank you very much!

#include \<TF1.h\>  
int main(int argc, char\*\* argv)  
{  
TF1\* f1 = new TF1(“f1”, “sin(x)/x” , 0, 10);  
f1-\>Draw();  
return 0;  
}

![2023-02-15 12_39_47-Clipboard](https://root-forum.cern.ch/uploads/default/original/3X/1/c/1cb62511388124452046ddb06dd2727ac72a269f.jpeg)

![2023-02-15 12_41_50-Clipboard](https://root-forum.cern.ch/uploads/default/original/3X/7/d/7d144cbfd6eaf16c01b78f8980f882c5c0222ea1.jpeg)

 ![2023-02-15 12_43_39-Clipboard](https://root-forum.cern.ch/uploads/default/original/3X/8/0/80069a32f9a6a5a9d4f6b29700189e99d9e7be2d.jpeg)

 ![2023-02-15 12_44_34-Clipboard](https://root-forum.cern.ch/uploads/default/original/3X/7/9/79442a3014895a2c4eaedaef55f8cbc265e4095e.jpeg)

 ![2023-02-15 12_45_38-Clipboard](https://root-forum.cern.ch/uploads/default/original/3X/6/7/67dd812b340ce80f6a1f763d345445d7b88cd4c5.jpeg)

---

<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:** [February 15, 2023, 7:43am UTC](https://root-forum.cern.ch/t/on-visual-studio-2022-root-running-problem/53636/2 "2023-02-15T07:43:03Z")

</div>

Welcome to the ROOT Forum!

Make sure you build with the same flags than the ones used to build ROOT. Since you only have one source file, I would suggest to build in the `x64 Native Tools Command Prompt for VS 2022`. Something like this:

```auto
cl -nologo -MD -GR -EHsc -Zc:__cplusplus -std:c++17 RooPlot.cxx -I %ROOTSYS%\include /link -LIBPATH:%ROOTSYS%\lib libCore.lib libGui.lib libHist.lib libGpad.lib

```

And if you want your program (your TCanvas) to stay open, you have to add an instance of `TApplication`. Something like:

```auto
#include <TApplication.h>
#include <TF1.h>

int main(int argc, char** argv)
{
   TApplication app("app", &argc, argv);
   TF1* f1 = new TF1("f1", "sin(x)/x" , 0, 10);
   f1->Draw();
   app.Run();
   return 0;
}

```

---

<div class="post-metadata">

**Author:** ![Billy](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/billy/32/32482_2.png) [@Billy](https://root-forum.cern.ch/u/Billy)\
**Post date:** [February 15, 2023, 9:10am UTC](https://root-forum.cern.ch/t/on-visual-studio-2022-root-running-problem/53636/3 "2023-02-15T09:10:54Z")

</div>

Thank you very much, Bellenot! It works!  
I also find a way to build and run from Visual studio 2022 IDE. No environment variable setting required. The compiled exe file needs to be put into the Root/bin folder.

Thanks again Bellenot.

---

<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:** [February 15, 2023, 9:14am UTC](https://root-forum.cern.ch/t/on-visual-studio-2022-root-running-problem/53636/4 "2023-02-15T09:14:37Z")

</div>

You’re very welcome! And note you can also simply add `%ROOTSYS%\bin` in your `PATH`
