I am getting a Clang compiler error when compiling ROOT script:
~/root_install/include/ROOT/RStringView.hxx:32:4: error: redefinition of 'basic_string_view' as different kind of symbol using basic_string_view = ::std::experimental::basic_string_view<_CharT,_Traits>;
/usr/include/c++/9/string_view:90:11: note: previous definition is here
class basic_string_view
This is the problematic code in ROOT library:
namespace std {
template<class _CharT, class _Traits = std::char_traits<_CharT> >
using basic_string_view = ::std::experimental::basic_string_view<_CharT,_Traits>;
// basic_string_view typedef names
typedef basic_string_view<char> string_view;
typedef basic_string_view<char16_t> u16string_view;
typedef basic_string_view<char32_t> u32string_view;
typedef basic_string_view<wchar_t> wstring_view;
// template<class _CharT, class _Traits = std::char_traits<_CharT> >
// basic_string_view<_CharT,_Traits>
// &operator=(basic_string_view<_CharT,_Traits> &lhs, const TString &rsh) {
// *lhs = basic_string_view<_CharT,_Traits>(rsh);
// return *lhs;
// }
#ifndef R__HAS_STOD_STRING_VIEW
inline double stod(std::string_view str, size_t *pos)
{
return std::stod(std::string(str.data(), str.size()),pos);
}
#endif
}
Is there a way to avoid this error without changing the library? Compiling it with g++ with following command works just fine:\
g++ -std=c++2a file.cpp `root-config --cflags --libs`
Edit:
Clang compile command:
clang -std=c++20 --include-directory ~/root_install/include file.cpp
ROOT can be compiled with clang++
(but not with clang
) using the following command:
clang++ file.C `root-config --cflags --libs`
This also works with the -std=c++20
flag.