Bugs in "TFile" when using C++17?

Sorry if this question is too basic; I am very new to ROOT. I am trying to compile a program using some ROOT header files and the following Makefile options:

CXX = g++
CXXFLAGS = -march=native `root-config --cflags --libs` -std=c++17 
LDFLAGS = `root-config --cflags --libs`

The result is a huge number of errors starting with the following (when using “TString.h”)

/usr/local/bin/root_v6.20.02/include/ROOT/RStringView.hxx:32:84: error: conflicting declaration of template ‘template<class _CharT, class _Traits> using basic_string_view = std::experimental::__ROOT::basic_string_view<_CharT, _Traits>’

and then the second error:

In file included from /usr/include/c++/7/memory:74:0,                                                             
                 from /usr/local/bin/root_v6.20.02/include/ROOT/TypeTraits.hxx:15,                                
                 from /usr/local/bin/root_v6.20.02/include/TString.h:29,                                          
                 from /usr/local/bin/root_v6.20.02/include/TNamed.h:26,                                           
                 from /usr/local/bin/root_v6.20.02/include/TDictionary.h:44,                                      
                 from /usr/local/bin/root_v6.20.02/include/TDataType.h:25,                                        
                 from /usr/local/bin/root_v6.20.02/include/TBuffer.h:24,                                          
                 from /usr/local/bin/root_v6.20.02/include/TDirectory.h:24,                                       
                 from /usr/local/bin/root_v6.20.02/include/TDirectoryFile.h:25,                                   
                 from /usr/local/bin/root_v6.20.02/include/TFile.h:27,                                            
                 from test.cpp:2:                                                                                 
/usr/include/c++/7/ext/concurrence.h:53:16: error: ‘_Lock_policy’ does not name a type                            
   static const _Lock_policy __default_lock_policy =                                                              
In file included from /usr/include/c++/7/iostream:38:0,                                                           
                 from test.cpp:1:                                                                                 
/usr/include/c++/7/ext/concurrence.h: In function ‘void std::__throw_concurrence_lock_error()’:                   
/usr/include/c++/7/ext/concurrence.h:102:5: error: ‘__concurrence_lock_error’ was not declared in this scope      
   { _GLIBCXX_THROW_OR_ABORT(__concurrence_lock_error()); }

I can get around this by not using TStrings directly in my code, but it seems that also the “TFile.h” header loads “TString.h” so the same problems arise. Is there an additional flag I can enable during compilation to avoid these conflicts? Or is it best to simply avoid the use of C++17 with ROOT?

Note: the above errors are not due to a fault in my code, they appear even when trying to compile a 3-line “Hello world” program

ROOT Version: 6.20/02
Platform: Linux (Ubuntu 18.04)
Compiler: g++ version 7.5.0

Hello and welcome to the ROOT forum!

The C++ compiler and standard for your program would need match the C++ standard with which ROOT has been compiled. You can check ROOT’s settings with root-config --cflags. If you compile ROOT yourself, you can enforce C++17 with the cmake option CMAKE_CXX_STANDARD 17.

As a side note, the CXXFLAGS variable would ideally only use root-config --cflags (without libs) and the LDFLAGS would use root-config --libs.


thanks very much!