# Enable C++14/17 support after building ROOT

**URL:** <https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735>\
**Category:** Newbie\
**Created:** [November 8, 2019, 11:10am UTC](https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735 "2019-11-08T11:10:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimd99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kimd99/32/20549_2.png) [@kimd99](https://root-forum.cern.ch/u/kimd99)\
**Post date:** [November 8, 2019, 11:10am UTC](https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735/1 "2019-11-08T11:10:29Z")

</div>

Hello,  
I am trying to compile macros with c++14/17 features, either with g+±9

```auto
g++-9 -std=c++17 -o simulation.exe particle.cpp main-particle.C `root-config --cflags --libs`

```

or with ACLiC

```auto
.L particle.cpp+
.L main-particle.C+

```

Building ROOT was my first experience with CMake and I did not set the flag -Dcxx17=ON. Having used inline variables, fold expressions and deduced return types, I get error messages and warnings. I notice the flag -std=c++17 is ignored, possibly because of root-config which comes after and sets c++11 support. Therefore I tried putting it at the end of the command, which results in compile errors in several ROOT headers, starting from:

```auto
In file included from /home/kimdamiani/Products/root/include/TString.h:28,
                 from /home/kimdamiani/Products/root/include/TNamed.h:26,
                 from /home/kimdamiani/Products/root/include/TRandom.h:25,
                 from main-particle.C:2:
/home/kimdamiani/Products/root/include/ROOT/RStringView.hxx:32:10: error: conflicting declaration of template ‘template<class _CharT, class _Traits> using basic_string_view = std::experimental::__ROOT::basic_string_view<_CharT, _Traits>’
   32 | using basic_string_view = ::std::experimental::basic_string_view<_CharT,_Traits>;
      | ^ ~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/9/bits/basic_string.h:48,
                 from /usr/include/c++/9/string:55,
                 from /usr/include/c++/9/bits/locale_classes.h:40,
                 from /usr/include/c++/9/bits/ios_base.h:41,
                 from /usr/include/c++/9/ios:42,
                 from /usr/include/c++/9/ostream:38,
                 from /usr/include/c++/9/iostream:39,
                 from main-particle.C:1:
/usr/include/c++/9/string_view:90:11: note: previous declaration ‘template<class _CharT, class _Traits> class std::basic_string_view’
   90 | class basic_string_view
      | ^ ~~~~~~~~~~~~~~~~

```

-the list goes on.

Is there any other flag I can add when compiling my macros or is deleting ROOT and building it again with -Dcxx17=ON the only option to support c++14/17 features?

Thank you in advance,  
Kim

\_ROOT Version: 6.18/04  
\_Platform: Ubuntu 19.04 x86\_64

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [November 8, 2019, 11:46am UTC](https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735/2 "2019-11-08T11:46:08Z")

</div>

Hi,

With latest ROOT version you should use following command for ROOT compilation:

```auto
cmake -DCMAKE_CXX_STANDARD=17 ...

```

Please check that is output of the command:

```auto
root-config --cflags

```

If ROOT compiled with default settings, c++11 will overwrite your c++17 flags.

You also can move `-std=c++17` after `root-config --cflags`.

Regards,  
Sergey

---

<div class="post-metadata">

**Author:** ![kimd99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kimd99/32/20549_2.png) [@kimd99](https://root-forum.cern.ch/u/kimd99)\
**Post date:** [November 9, 2019, 12:10am UTC](https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735/3 "2019-11-09T00:10:23Z")

</div>

Thank you for the explanation.

I did use the default settings to compile ROOT (at the time I didn’t know I had to add the option for c++17) , so I get:

```auto
$ root-config --cflags
-pthread -std=c++11 -m64 -I/home/kimdamiani/Products/root/include

```

The problem is that if I move -std=c++17 at the end of the command, writing:

```auto
g++-9 -o simulation.exe particle.cpp main-particle.C `root-config --cflags --libs` -std=c++17

```

I get the list of errors in ROOT headers I mentioned before, for example non-matching declarations, use of the incomplete type TString, use of non-template classes as templates and entities defined in namespace std which are not qualified and therefore are undeclared.

[errors-root-headers.txt](https://root-forum.cern.ch/uploads/short-url/vEtPx7fbfIN80w2q7WYa3TnlV2.txt) (152.7 KB)

The same happens if I modify directly the --cflags variable in the root-config file, changing -std=c++11 to -std=c++17, though I understand that it may not be a good idea because there are other parts of ROOT which still have the default settings in terms of support for c++11.

EDIT: I have the same problem even if I try to compile a simple test program:

```auto
//test.C
#include "TRandom.h"
#include "TMath.h"
void generate(){}

int main(){
	generate();
	return 0;
}

```

with the command

```auto
g++ test.C `root-config --cflags --libs` -std=c++17

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [November 9, 2019, 6:09pm UTC](https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735/4 "2019-11-09T18:09:47Z")

</div>

I’m afraid, you will need to [build your ROOT](https://root.cern.ch/building-root) from scratch, adding “[-Dcxx17=ON](https://root.cern.ch/building-root#options)” (note that, with this new version, you will not be able to “downgrade” the standard using “-std=c++14” nor “-std=c++11” command line options).

With your current ROOT version, which uses the default “[-Dcxx11=ON](https://root.cern.ch/building-root#options)”, you may be able to “upgrade” the standard using the “-std=c++14” command line option:

```bash
`root-config --cxx --cflags` -std=c++14 test.C `root-config --libs`

```

---

<div class="post-metadata">

**Author:** ![kimd99](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/kimd99/32/20549_2.png) [@kimd99](https://root-forum.cern.ch/u/kimd99)\
**Post date:** [November 17, 2019, 9:49am UTC](https://root-forum.cern.ch/t/enable-c-14-17-support-after-building-root/36735/5 "2019-11-17T09:49:18Z")

</div>

Thank you very much!
