Compiling root6 with visual studio (again!)


Please read tips for efficient and successful posting and posting code

Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.

ROOT Version: 6.30.04
Platform: win11
Compiler: vs2022


Hello,
after re-installing root on a new computer, I installed my known working version of root 5 but was tempted to attempt to switch that to the latest version of Root 6 as above.
The rationale is that there is a binary version of root to download that says Visual Studio 2022 x64.

I speculated that if such a version is released then it would actually work. I was also promissed two years ago that some incompatibilities that existed at that time, would be resolved in the next version (two years ago).

So full of optimism I tried compiling my code with the above version of root. Compiler options are as follows

/permissive /ifcOutput “x64\Release" /GS /GL /W3 /Gy /Zc:wchar_t /Zi /Gm- /O2 /sdl /Fd"x64\Release\vc143.pdb” /Zc:inline /fp:precise /D “NDEBUG” /D “_CONSOLE” /D “_UNICODE” /D “UNICODE” /errorReport:prompt /WX- /Zc:forScope /Gd /Oi /MD /std:c++17 /FC /Fa"x64\Release" /EHsc /nologo /Fo"x64\Release" /Fp"x64\Release\GMD_L2.pch" /diagnostics:column

NB the /permissive flag was initially not activated, but didn’t make much difference either way.

I am using the following tools configuration

And this is the latest installation of VS2022

Unfortunately I seem to be getting very similar compile errors as two years ago:

All around the same spot in TVirtualTreePlayer

Any ideas?

To be sure to be binary compatible, I would use the same flags than the ones used to build ROOT. You can type root-config --cflags on the command prompt to list them. For example:

C:\root-dev\rootdev>root-config --cflags
 -nologo -Zc:__cplusplus -std:c++17 -MD -GR -EHsc- -W3 -D_WIN32 -O2 -IC:\root-dev\build\x64\debug\include

(but check with your version)
And I would suggest to use CMake to configure and generate your project, it should be compatible then.

Hi Bellenot, thanks for that, so I have recreated a project as a CMake project in VS and I did generate the root compile flags as you suggested from the root-config command.

Then, in the cmake file I print the current compiler options. I can reset those with the options that were indicated by the root-config command (and delete any options that are not mentioned).

The question is, do i leave the linker options as they are? There is nothing special about linker options I need to take care of correct?

Thanks
Dimitris

Here is a simple CMakelists.txt example, to put in your source directory:

# Check if cmake has the required version
CMAKE_MINIMUM_REQUIRED(VERSION 3.16 FATAL_ERROR)

set(PROJECT_NAME test)
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})

add_executable(${PROJECT_NAME} test.cxx )
target_link_libraries(${PROJECT_NAME} ${ROOT_LIBRARIES})

Then, in a x64 Native Tools Command Prompt for VS 2022, cd to your build directory and type:

cmake -G"Visual Studio 17 2022" -A x64 -Thost=x64 -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_INSTALL_PREFIX=../install_directory ../source_directory

(replace ../install_directory and ../source_directory with your own)
And then build with:

cmake --build . --config Release

No need to care about compiler or linker flags, they will be set by CMake

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