TString error: no template named 'basic_string_view'

Hi,
I am able to work with ROOT on my mac, visualization and analyzing PREPARED .root data, but when I want to compile a code with #include<TROOT.h>, I have some errors like:
typedef basic_string_view string_view;

./RStringView.h:36:12: error: no template named ‘basic_string_view’
typedef basic_string_view<char16_t> u16string_view;

./RStringView.h:37:12: error: no template named ‘basic_string_view’
typedef basic_string_view<char32_t> u32string_view;

./RStringView.h:38:12: error: no template named ‘basic_string_view’
typedef basic_string_view<wchar_t> wstring_view;
^
./RStringView.h:50:28: error: no member named ‘to_string’ in
‘std::__1::basic_string_view<char, std::__1::char_traits >’
return std::stod(str.to_string(),pos);

Can you help me, to find out a solution.

Thanks
Behrouz


_ROOT Version:6.06/04
Platform: Not Provided
Compiler: Not Provided


Which c++ version are you using? You need to use the same C++ standard when compiling ROOT and when compiling your own software. Reason: ROOT defines its own std::string_view if that is not provided by the compiler.

What does root-config --cflags output? You need the same -std=XXXXX setting when compiling your own code.

Thanks!
in both, the C++ version is “c++11”

Can you send the compiler invocation and the error messages? (I.e. the full log.)

Without using ROOT classes (i.e. #include <TROOT.h> OR #include <TString.h>), there is no any problem but if I want to use them some error will appear.
This is the messages after compiling:

g++ -DHAVE_CONFIG_H -I. -I… -I/Users/behrouzkhiali/AMS-02/solar_prop/cfitsio/include -I/Users/behrouzkhiali/AMS-02/solar_prop/CCfits/CCfits/include -I/Users/behrouzkhiali/AMS-02/sp/cfitsio/lib/include -I/Users/behrouzkhiali/AMS-02/sp/CCfits/include -g -O2 -std=c++11 -MT main.o -MD -MP -MF .deps/main.Tpo -c -o main.o main.cc
mv -f .deps/main.Tpo .deps/main.Po
g++ -DHAVE_CONFIG_H -I. -I… -I/Users/behrouzkhiali/AMS-02/solar_prop/cfitsio/include -I/Users/behrouzkhiali/AMS-02/solar_prop/CCfits/CCfits/include -I/Users/behrouzkhiali/AMS-02/sp/cfitsio/lib/include -I/Users/behrouzkhiali/AMS-02/sp/CCfits/include -g -O2 -std=c++11 -MT constants.o -MD -MP -MF .deps/constants.Tpo -c -o constants.o constants.cc
mv -f .deps/constants.Tpo .deps/constants.Po
g++ -DHAVE_CONFIG_H -I. -I… -I/Users/behrouzkhiali/AMS-02/solar_prop/cfitsio/include -I/Users/behrouzkhiali/AMS-02/solar_prop/CCfits/CCfits/include -I/Users/behrouzkhiali/AMS-02/sp/cfitsio/lib/include -I/Users/behrouzkhiali/AMS-02/sp/CCfits/include -g -O2 -std=c++11 -MT density.o -MD -MP -MF .deps/density.Tpo -c -o density.o density.cc
mv -f .deps/density.Tpo .deps/density.Po
g++ -DHAVE_CONFIG_H -I. -I… -I/Users/behrouzkhiali/AMS-02/solar_prop/cfitsio/include -I/Users/behrouzkhiali/AMS-02/solar_prop/CCfits/CCfits/include -I/Users/behrouzkhiali/AMS-02/sp/cfitsio/lib/include -I/Users/behrouzkhiali/AMS-02/sp/CCfits/include -g -O2 -std=c++11 -MT fileHelper.o -MD -MP -MF .deps/fileHelper.Tpo -c -o fileHelper.o fileHelper.cc
mv -f .deps/fileHelper.Tpo .deps/fileHelper.Po
g++ -DHAVE_CONFIG_H -I. -I… -I/Users/behrouzkhiali/AMS-02/solar_prop/cfitsio/include -I/Users/behrouzkhiali/AMS-02/solar_prop/CCfits/CCfits/include -I/Users/behrouzkhiali/AMS-02/sp/cfitsio/lib/include -I/Users/behrouzkhiali/AMS-02/sp/CCfits/include -g -O2 -std=c++11 -MT particle.o -MD -MP -MF .deps/particle.Tpo -c -o particle.o particle.cc
In file included from particle.cc:21:
In file included from ./TROOT.h:29:
In file included from ./TDirectory.h:25:
In file included from ./TNamed.h:29:
In file included from ./TString.h:41:
./RStringView.h:35:12: error: no template named ‘basic_string_view’
typedef basic_string_view string_view;
^
./RStringView.h:36:12: error: no template named ‘basic_string_view’
typedef basic_string_view<char16_t> u16string_view;
^
./RStringView.h:37:12: error: no template named ‘basic_string_view’
typedef basic_string_view<char32_t> u32string_view;
^
./RStringView.h:38:12: error: no template named ‘basic_string_view’
typedef basic_string_view<wchar_t> wstring_view;
^
./RStringView.h:50:28: error: no member named ‘to_string’ in ‘std::__1::basic_string_view<char, std::__1::char_traits >’
return std::stod(str.to_string(),pos);
~~~ ^
In file included from particle.cc:21:
In file included from ./TROOT.h:29:
In file included from ./TDirectory.h:25:
In file included from ./TNamed.h:29:
./TString.h:117:75: error: no member named ‘to_string’ in ‘std::__1::basic_string_view<char, std::__1::char_traits >’
operator std::string() const { return std::string_view(Data(),fExtent).to_string(); }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ^
6 errors generated.
make: *** [particle.o] Error 1

From the shown output, it seems to me that you copied ROOT includes (from some unknown ROOT version) to your “current directory” (i.e. “./”) which doesn’t really seem like the right thing to do to me (or am I wrong?).

BTW. You need to specify your “operating system” and your “compiler” versions (you specified only that you were using an outdated ROOT 6.06/04 which will break on newer systems / compilers).

the compiler and OS versions are gcc-4.2.1 and x86_64
However, I installed the ROOT latest version, and it didn’t solve yet

OS version … should be something like “Ubuntu 14.04” or “CentOS 7” or … plus the “architecture” (which is “x86_64” in your case).

You need gcc 4.8 or newer for ROOT 6.

Thanks for your response,
My OS version is MacOS High Sierra 10.13.6

In this case you probably need to use the “clang” compiler (make sure that your ROOT, and your another source code, was compiled with the same “clang” version that you try to use now).

ROOT Forum -> Search -> “mac basic_string_view”

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