如何在C ++ 17中使用CERN Root?

用户名

显然,CERN的“ Root”软件与C ++ 17兼容(从6.12版开始)。但是,我完全无法使用最新版本(6.20)来工作,而我在该主题上发现的所有先前问题都来自几年前。

有根经验的人是否知道是否有特定的编译器选项来使其与C ++ 17一起使用?


尝试编译琐碎的“ Hello world”程序时遇到的错误示例:

  • 以下是(我认为)由于“ TFile.h”标头隐式加载“ 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>
  • 另一个错误(至少对我来说更神秘)的示例是:
/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()); }                                                       
     ^                                                                                                            
/usr/include/c++/7/ext/concurrence.h:102:5: note: suggested alternative:                                          
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/TKey.h:15,                                             
                 from /usr/local/bin/root_v6.20.02/include/TBasket.h:28,                                          
                 from /usr/local/bin/root_v6.20.02/include/ROOT/TIOFeatures.hxx:14,                               
                 from /usr/local/bin/root_v6.20.02/include/TTree.h:30,                                            
                 from /usr/local/bin/root_v6.20.02/include/TNtuple.h:24,                                          
                 from test.cpp:2:                                                                                 
/usr/include/c++/7/ext/concurrence.h:67:9: note:   ‘__gnu_cxx::__concurrence_lock_error’                          
   class __concurrence_lock_error : public std::exception 

我正在Linux上使用最新版本的g ++和Root,并且我的Makefile中具有以下选项:

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

关于可能的解决方法的任何评论将不胜感激,或者也许我需要在Makefile中添加一些其他选项?知道在使用Root库时是否建议坚持使用C ++ 11/14也很有帮助。

Pseyfert

您只能将root与已编译根版本的c ++标准一起使用。这是一个已知的不便之处,我相信如果/当他们解决这些问题时,开发人员将很高兴。构建配置root-config --cflags应设置适当的c ++标准。这很可能是c ++ 17(适合我)

pseyfert@robusta:~ > root-config --cflags
-pthread -std=c++17 -m64 -fdiagnostics-color -march=native -Wextra -Wall -Wshadow -I/home/pseyfert/coding/root-install/include

如果您从源代码编译根目录,则要设置的生成选项是CMAKE_CXX_STANDARD=17cxx17=ONdoc),以使用c ++ 17编译根目录并在所有下游项目中使用c ++ 17。

如果您使用root的二进制安装,则由提供构建的人员来完成切换。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章