Windows: non-matching standards error building a project with ROOT dependencies

I am trying to build a project with has ROOT dependencies (I believe because output is being written to a .root file).

When trying to build the project, I get many The C++ standard in this build does not match ROOT configuration (201703L) errors.

I compiled Geant4 and ROOT from source using Visual Studio 17. At the time I did not specify any standard, so assuming it defaults to some sort of ‘latest’ I don’t understand why there would be a difference between them.

Similarly, I don’t specify a standard when I am building the project, so I am unsure how to proceed. Any help would be brilliant.

In case it is helpful, I have included the cmake file for the project build:

#cmake_minimum_required(VERSION 2.8)
#target_link_libraries(SBS ${Geant4_LIBRARIES})
# Setup the project
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
find_package(Geant4 REQUIRED)
## Get the ROOT config
set(ROOT_DIR "C:/path/to/root_v6.28/cmake")
find_package(ROOT "6.27" REQUIRED)

#include_directories(${Geant4_INCLUDE_DIRS} ${INC_ROOT})


# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
  find_package(Geant4 REQUIRED ui_all vis_all)
  find_package(Geant4 REQUIRED)

# Setup Geant4 include directories and compile definitions
# Setup include directory for this project
include_directories(${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/objects/include ${INC_ROOT})

# Locate sources and headers for this project
# NB: headers are included so they will show up in IDEs
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc ${PROJECT_SOURCE_DIR}/objects/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh ${PROJECT_SOURCE_DIR}/objects/*.hh)

#file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
#file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)

# Add the executable, and link it to the Geant4 libraries
add_executable(${PROJECT_NAME} ${PROJECT_NAME}.cc ${sources} ${headers})
target_link_libraries(${PROJECT_NAME} ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})
# Install the executable to 'bin' directory under CMAKE_INSTALL_PREFIX

Which version of Geant4 is being used (this will determine the default C++ standard compiled against)?

I’d also suggest updating the line:

cmake_minimum_required(VERSION 3.0 FATAL_ERROR)


cmake_minimum_required(VERSION 3.16...3.24)

as 3.0 and associated policies won’t support the latest C++ standards well, if at all.

I am using Geant4 v11.1.0.
I am trying to combine this with ROOT v6.28.0 (latest-stable).

this will determine the default C++ standard compiled against

I am completely new to compiling code in Windows. Can this be explicitly set instead, within the limits of what is supported. I am building with VS as per the install instructions.

I checked, and in my VS Developer command prompt, cmake version 3.52.2 is being used.

Does 3.16...3.24 indicate a range, and if so, could having a higher version be causing the problem?

Thanks for the info! O.k., Geant4 11.1 will build using C++17 by default, so that’s fine. I think ROOT still defaults to C++11, so if you’re compiling that from source, it should suffice to add -DCMAKE_CXX_STANDARD=17 to the CMake arguments you passed to configure and install ROOT.

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