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

Hi,
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)
#add_executable(SBS SBS.cc)
#target_link_libraries(SBS ${Geant4_LIBRARIES})
#----------------------------------------------------------------------------
# Setup the project
#
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(MuSim)
find_package(Geant4 REQUIRED)
##
## Get the ROOT config
set(ROOT_DIR "C:/path/to/root_v6.28/cmake")
find_package(ROOT "6.27" REQUIRED)
set(INC_ROOT ${ROOT_INCLUDE_DIRS})
set(LIB_ROOT ${ROOT_LIBRARY_DIR})

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

add_definitions(${Geant4_CXX_FLAGS})
set(CMAKE_CXX_FLAGS "${Geant4_CXX_FLAGS}")


#----------------------------------------------------------------------------
# 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(GEANT4_INSTALL_DATA "Data" ON)
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
  find_package(Geant4 REQUIRED ui_all vis_all)
else()
  find_package(Geant4 REQUIRED)
endif()

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

#----------------------------------------------------------------------------
# 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
#
install(TARGETS ${PROJECT_NAME} DESTINATION bin)


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)

to

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.