Compilation error on root 6.24

Hi,

I’ve developed a cmake library depending on root 6.26 which stdc++17, but I need to use it with root 6.24, so I’ve changed the stdc++ flag to stdc++14.
But I’m not able to compile my library due to an error in root RStringView.hxx headers
I shared with you my CMakeFile content:

## Vesion and policy setup
# Debian stable 2023
cmake_minimum_required(VERSION 3.18)

if(${CMAKE_VERSION} VERSION_LESS 3.25)
  cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else()
  cmake_policy(VERSION 3.25)
endif()

## Compile options

if(NOT CMAKE_BUILD_TYPE)
  set(CMAKE_BUILD_TYPE Release)
endif()

set(ROOSTER_DEFAULT_COMPILE_OPTIONS -Wall -Wextra -Wpedantic)

if(CMAKE_BUILD_TYPE STREQUAL Release)
  set(ROOSTER_DEFAULT_COMPILE_OPTIONS "${ROOSTER_DEFAULT_COMPILE_OPTIONS}" -O3)
else()
  set(ROOSTER_DEFAULT_COMPILE_OPTIONS "${ROOSTER_DEFAULT_COMPILE_OPTIONS}" -g -ggdb)
endif()

if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
  set(ROOSTER_DEFAULT_COMPILE_OPTIONS "${ROOSTER_DEFAULT_COMPILE_OPTIONS}" -ferror-limit=5)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
  set(ROOSTER_DEFAULT_COMPILE_OPTIONS "${ROOSTER_DEFAULT_COMPILE_OPTIONS}" -fmax-errors=5)
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")

elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")

endif()


## Project setup
project(Rooster
  LANGUAGES CXX
)

set(ROOSTER_NUSIM_DIR "${CMAKE_CURRENT_SOURCE_DIR}/Nusimulation")
set(ROOSTER_NUDATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/NuData")
set(ROOSTER_RESMOD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/NuResponseModel")

## find and link dependancies
find_package(ROOT 6.20 CONFIG REQUIRED)

## Cling dict generation
root_generate_dictionary(G__NuSimulation "${ROOSTER_NUSIM_DIR}/NuSimulation.h" LINKDEF "${ROOSTER_NUSIM_DIR}/NuSimulation_LinkDef.h")
root_generate_dictionary(G__NuData "${ROOSTER_NUDATA_DIR}/OscillationFit.h" LINKDEF "${ROOSTER_NUDATA_DIR}/NuData_LinkDef.h")
# root_generate_dictionary(G__NuResponseModel "${ROOSTER_RESMOD_DIR}/NuResponseModel.h" LINKDEF "${ROOSTER_RESMOD_DIR}/NuResponseModel_LinkDef.h")

## Make Nu Simulation target witch old roofit object functions
add_library(NuSimulation SHARED
  "${ROOSTER_NUSIM_DIR}/RooNewCBShape.cxx" "${ROOSTER_NUSIM_DIR}/RooNewCBShape.h"
  "${ROOSTER_NUSIM_DIR}/RSTEtrueParamPdf.cxx" "${ROOSTER_NUSIM_DIR}/RSTEtrueParamPdf.h"
  "${ROOSTER_NUSIM_DIR}/constants.hpp"
  "${ROOSTER_NUSIM_DIR}/specialIntegral.h"
  "${ROOSTER_NUSIM_DIR}/NuSimulation.h"
  G__NuSimulation.cxx)
target_include_directories(NuSimulation PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(NuSimulation PUBLIC ROOT::RooFit ROOT::RooStats ROOT::Core)
target_compile_options(NuSimulation PRIVATE "${ROOSTER_DEFAULT_COMPILE_OPTIONS}")
target_compile_features(NuSimulation PRIVATE cxx_std_14)
set_target_properties(NuSimulation PROPERTIES CXX_EXTENSIONS OFF)

add_library(NuData SHARED 
  "${ROOSTER_NUDATA_DIR}/OscillationFit.cxx" "${ROOSTER_NUDATA_DIR}/OscillationFit.h"
  "${ROOSTER_NUDATA_DIR}/FluctuateAsimovPseudoData.cxx" "${ROOSTER_NUDATA_DIR}/FluctuateAsimovPseudoData.h"
  "${ROOSTER_NUDATA_DIR}/EmptyBinsAsInPhaseIIdata.cxx" "${ROOSTER_NUDATA_DIR}/EmptyBinsAsInPhaseIIdata.h"
  "${ROOSTER_NUDATA_DIR}/NuData.h"
  G__NuData.cxx)
target_include_directories(NuData PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}")
target_link_libraries(NuData PUBLIC NuSimulation ROOT::Spectrum)
target_compile_options(NuData PRIVATE "${ROOSTER_DEFAULT_COMPILE_OPTIONS}")
target_compile_features(NuData PRIVATE cxx_std_14)
set_target_properties(NuData PROPERTIES CXX_EXTENSIONS OFF)



## Make the executables
add_executable(nu_data "${ROOSTER_NUDATA_DIR}/main.cpp" "${ROOSTER_NUDATA_DIR}/NuData.h")
target_link_libraries(nu_data PUBLIC NuData)
target_compile_options(nu_data PRIVATE "${ROOSTER_DEFAULT_COMPILE_OPTIONS}")
target_compile_features(nu_data PRIVATE cxx_std_14)
set_target_properties(nu_data PROPERTIES CXX_EXTENSIONS OFF)

add_executable(response_model
  "${ROOSTER_RESMOD_DIR}/toml.hpp"
  "${ROOSTER_RESMOD_DIR}/independant_fit0.cpp" "${ROOSTER_RESMOD_DIR}/independant_fit1.cpp" "${ROOSTER_RESMOD_DIR}/independant_fit5.cpp"
  "${ROOSTER_RESMOD_DIR}/simultaneous_fit2.cpp" "${ROOSTER_RESMOD_DIR}/simultaneous_fit3.cpp" "${ROOSTER_RESMOD_DIR}/simultaneous_fit4.cpp" "${ROOSTER_RESMOD_DIR}/simultaneous_fit6.cpp" "${ROOSTER_RESMOD_DIR}/simultaneous_fit7.cpp"
  "${ROOSTER_RESMOD_DIR}/response_model.cpp" "${ROOSTER_RESMOD_DIR}/response_model.hpp"
  "${ROOSTER_RESMOD_DIR}/main.cpp")
target_link_libraries(response_model PUBLIC NuSimulation ROOT::ROOTVecOps ROOT::ROOTDataFrame)
target_compile_options(response_model PRIVATE "${ROOSTER_DEFAULT_COMPILE_OPTIONS}")
target_compile_features(response_model PRIVATE cxx_std_14)
set_target_properties(response_model PROPERTIES CXX_EXTENSIONS OFF)

(It’s really messy, sorry :confused: )
And there is the compilation error:

make
[  4%] Generating G__NuSimulation.cxx, libNuSimulation_rdict.pcm, libNuSimulation.rootmap
[  8%] Building CXX object CMakeFiles/NuSimulation.dir/Nusimulation/RooNewCBShape.cxx.o
/sps/stereo/yquerlioz/Workspace/rooster/Nusimulation/RooNewCBShape.cxx:39:24: warning: extra ';' [-Wpedantic]
   39 | ClassImp(RooNewCBShape);
      |                        ^
[ 12%] Building CXX object CMakeFiles/NuSimulation.dir/Nusimulation/RSTEtrueParamPdf.cxx.o
/sps/stereo/yquerlioz/Workspace/rooster/Nusimulation/RSTEtrueParamPdf.cxx:66:27: warning: extra ';' [-Wpedantic]
   66 | ClassImp(RSTEtrueParamPdf);
      |                           ^
[ 16%] Building CXX object CMakeFiles/NuSimulation.dir/G__NuSimulation.cxx.o
[ 20%] Linking CXX shared library libNuSimulation.so
[ 20%] Built target NuSimulation
[ 25%] Generating G__NuData.cxx, libNuData_rdict.pcm, libNuData.rootmap
[ 29%] Building CXX object CMakeFiles/NuData.dir/NuData/OscillationFit.cxx.o
In file included from /pbs/software/centos-7-x86_64/root/6.24.06/include/root/ROOT/RStringView.hxx:24,
                 from /pbs/software/centos-7-x86_64/root/6.24.06/include/root/TString.h:29,
                 from /sps/stereo/yquerlioz/Workspace/rooster/NuData/OscillationFit.cxx:1:
/sps/stereo/yquerlioz/Workspace/rooster/Nusimulation/constants.hpp:42:53:   in 'constexpr' expansion of 'std::experimental::fundamentals_v1::basic_string_view<char>(((const char*)"VARIABLE"))'
/opt/rh/devtoolset-9/root/usr/include/c++/9/experimental/string_view:109:58: error: call to non-'constexpr' function 'static std::size_t std::char_traits<char>::length(const char_type*)'
  109 |       : _M_len{__str == nullptr ? 0 : traits_type::length(__str)},
      |                                       ~~~~~~~~~~~~~~~~~~~^~~~~~~
/sps/stereo/yquerlioz/Workspace/rooster/Nusimulation/constants.hpp:43:57:   in 'constexpr' expansion of 'std::experimental::fundamentals_v1::basic_string_view<char>(((const char*)"PARAMETRIC"))'
/opt/rh/devtoolset-9/root/usr/include/c++/9/experimental/string_view:109:58: error: call to non-'constexpr' function 'static std::size_t std::char_traits<char>::length(const char_type*)'
/sps/stereo/yquerlioz/Workspace/rooster/NuData/OscillationFit.cxx: In function 'void oscillationFit(TString, TString, double, double, bool, bool, bool, int, bool, int)':
/sps/stereo/yquerlioz/Workspace/rooster/NuData/OscillationFit.cxx:966:16: warning: ISO C++ forbids variable length array 'candidateParams' [-Wvla]
  966 |     RooArgSet *candidateParams[nPeaks];
      |                ^~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/NuData.dir/NuData/OscillationFit.cxx.o] Error 1
make[1]: *** [CMakeFiles/NuData.dir/all] Error 2
make: *** [all] Error 2

If anyone has the slightest clue as to what’s going on it will be amazing.

Cheers,

Yann.


_ROOT Version: ROOT 6.24/06 (GCC) 9.3.1
_Platform: centos os
_Compiler: gcc 9.3.1


Check (compiler and standard): root-config --cxx --cflags

BTW. See also: ROOT Forum → Search → devtoolset

Hi :smiley:

I have checked root config before posting, that’s how I realized that the c++ standard used wasn’t the same.

>root-config --cxx --cflags
c++ -pthread -std=c++14 -m64 -I/pbs/software/centos-7-x86_64/root/6.24.06/include/root

I’m not trying to compile root from source, the version available should be a prebuild one.

Yann.

Are you sure these ROOT binaries were built with the “/opt/rh/devtoolset-9”?