Namespace errors

ROOT Version: 6.24/02
Platform: Ubuntu 20.04.2 (focal)
Compiler: Not Provided (uncertain)


Hello,

I am trying to make a program which depends on ROOT. I recently downloaded and built ROOT with the recommended setup, however added the DCMAKE_CXX_STANDARD=17 flag as I thought this would fix my issue. Evidently it didn’t.

When I run make on my local program I get errors like

home/[...]/root_install/include/ROOT/RStringView.hxx(65): error: namespace "std" has no member "string_view"
/home/[...]/root_install/include/ROOT/RStringView.hxx(84): error: expected an operator
/home/[...]/root_install/include/TString.h(115): error: expected an operator
/home/[...]/root_install/include/TString.h(280): error: namespace "std" has no member "string_view"

Looking online this seems to stem from C++ version mismatch, but I thought I took care of that with the cmake flag in both ROOT and my local program (with set(CXXFLAGS "${CXXFLAGS} -std=c++17"))

I’m not sure what other information I should provide for this as I’m honestly not very familiar with this entire building process. If further info is needed please feel free to ask, if anybody know how I should go about fixing this issue I would greatly appreciate it.

Sincerely,

Ronan

however added the DCMAKE_CXX_STANDARD=17

That flag is indeed require, however make sure you use it from the start. i.e. you need to start a build of ROOT from scratch with that option.

If from scratch you mean right after the download this is what I did. Though if that is thought to be the reason why I have this issue I can try to build it again and see.

The other potential reason is that the flag -std=c++17 might not be used as expected in your build. So you should also examine the actual command line use to compile your local program.

Ok, so I tried a rebuild which for some reason didn’t use C++17 but C++14 bbased of root-config output.

So just to be clear, my build command, following : Building ROOT from source - ROOT
Should actually be:
cmake -DCMAKE_CXX_STANDARD=17 -DCMAKE_INSTALL_PREFIX=../root_install/ ../root_src/ correct? I see other posts mentioning -Dcxx17=ON (Enable C++14/17 support after building ROOT) would this also be needed?

cxx17 is the old way of configuring and CMAKE_CXX_STANDARD is the new way.

With v6.24/02, CMAKE_CXX_STANDARD should have worked. What did the configure step print?

Ah, a re-build worked out fine so I assume I just made a typo or something. current output of root-config --cflags is -pthread -std=c++17 -m64 -I/home/[...]/root_install/include

I still get now the same initial issues, so it may be a build portion of the project I’m working with that’s an issue as you had mentioned earlier.

Hopefully without going too far off topic, if c++17 is required for this version of root, is there a reason why it is not recommended in the build page to use that argument? I may be misunderstanding the issue at hand.

c++17 is not required. What is required is that your project and ROOT are build using the same C++ standard (either c++11, c++14 or c++17).

Just a quick update. I did manage to resolve this by forcing ROOT to compile in C++11 which was in turn compatible with my other software, per pcanal’s guess.

Thank you for the help!