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

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


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:

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:

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

Thank you! I will try this command:)

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

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.