# Where can I find tutorials for building code with Visual C++?

**URL:** <https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015>\
**Category:** Newbie\
**Created:** [April 16, 2024, 10:38am UTC](https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015 "2024-04-16T10:38:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![phoenixAspies](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phoenixaspies/32/25456_2.png) [@phoenixAspies](https://root-forum.cern.ch/u/phoenixAspies)\
**Post date:** [April 16, 2024, 10:38am UTC](https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015/1 "2024-04-16T10:38:23Z")

</div>

Hello, I mainly write and debug code under Linux, but occasionally I need to test code by using Visual C++. I found it very difficult to compile code with Visual C++ because I couldn’t find any tutorial to teach me how to set parameters and libraries.  
For example, in linux I use this code to compile:g++ A.cpp -o A `root-config --cflags --libs`, but in Visual C++ I don’t know how to specify these parameters.

Could anyone kindly tell me where I can find a tutorial on building a ROOT based program with Visual C++?

\_ROOT Version: 6.22.08  
\_Platform: Windows 10  
\_Compiler: Visual Studio 2022

* * *

---

<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:** [April 16, 2024, 11:05am UTC](https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015/2 "2024-04-16T11:05:30Z")

</div>

AFAIK, there is no such tutorial… But you can try the following: In a Visual Studio Command Prompt, after having properly called `thisroot.bat` from the ROOT bin directory, call (like on Linux) `root-config --cflags --libs`:

```cmd
C:\root-dev>build\x64\release\bin\thisroot.bat

C:\root-dev>root-config --cflags --glibs
-nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -IC:\root-dev\build\x64\release\include /link -LIBPATH:C:\root-dev\build\x64\release\lib libCore.lib libImt.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGraf3d.lib libGpad.lib libROOTVecOps.lib libTree.lib libTreePlayer.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libThread.lib libGui.lib
C:\root-dev>

```

Then you can copy the result to your command line as argument to the compiler (cl.exe). For example:

```cmd
C:\root-dev>cl -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 dlopen.cxx -IC:\root-dev\build\x64\release\include /link -LIBPATH:C:\root-dev\build\x64\release\lib libCore.lib libImt.lib libRIO.lib libNet.lib libHist.lib libGraf.lib libGraf3d.lib libGpad.lib libROOTVecOps.lib libTree.lib libTreePlayer.lib libRint.lib libPostscript.lib libMatrix.lib libPhysics.lib libMathCore.lib libThread.lib
dlopen.cxx

```

---

<div class="post-metadata">

**Author:** ![phoenixAspies](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phoenixaspies/32/25456_2.png) [@phoenixAspies](https://root-forum.cern.ch/u/phoenixAspies)\
**Post date:** [April 16, 2024, 11:22am UTC](https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015/3 "2024-04-16T11:22:36Z")

</div>

Thank you! I will try this command:)

---

<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:** [April 16, 2024, 11:23am UTC](https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015/4 "2024-04-16T11:23:38Z")

</div>

You’re welcome! And obviously replace the `dlopen.cxx` in the command by your own source file(s)

---

<div class="post-metadata">

**Author:** ![phoenixAspies](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/phoenixaspies/32/25456_2.png) [@phoenixAspies](https://root-forum.cern.ch/u/phoenixAspies)\
**Post date:** [April 18, 2024, 4:22pm UTC](https://root-forum.cern.ch/t/where-can-i-find-tutorials-for-building-code-with-visual-c/59015/5 "2024-04-18T16:22:27Z")

</div>

Hi,I finally find the solution to compile and run codes.  
The solution(for 6.26.14&VS2022) is:  
0.add environment variables to System Variables as in thisroot.bat wrote.  
1.add flag “/DLINUX\_PATH\_SEPARATOR”(for Visual Studio) or “-DLINUX\_PATH\_SEPARATOR”(g++ for Windows)(C/C+±\>Commands)  
2.set correct LIBRARY and INCLUDE filepath in “VC++ directory”  
3.add libCore.lib,libCling.lib,libRIO.lib,libNet.lib,libHist.lib,libGraf.lib,libGraf3d.lib,libGpad.lib,libTree.lib,libRint.lib,libPostscript.lib,libMatrix.lib,libPhysics.lib,libMathCore.lib,libThread.lib ( or some other lib shown by `root-config --cflags --libs` )to “Linker/Input/Additional Dependencies”  
4.compile succeeded.
