【问题标题】:how can I use CERN Root with C++17?如何在 C++17 中使用 CERN Root?
【发布时间】:2020-10-21 11:21:26
【问题描述】:

Apparently,CERN 的“Root”软件与 C++17 兼容(从 6.12 版开始)。但是,我完全无法让它与最新版本 (6.20) 一起使用,而且我在这个主题上发现的所有以前的问题都是几年前的。

有 Root 经验的人是否知道是否有特定的编译器选项可以使其与 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`

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

【问题讨论】:

    标签: c++ c++17 root-framework


    【解决方案1】:

    您只能将 root 用于编译您的 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
    

    如果您从源代码编译 root,那么 CMAKE_CXX_STANDARD=17cxx17=ON (doc) 是您要设置的构建选项,以使用 c++17 编译 root 并在所有下游项目中使用 c++17。

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

    【讨论】:

      猜你喜欢
      • 2011-04-26
      • 2012-07-12
      • 2012-05-31
      • 2019-08-16
      • 2011-11-23
      • 2018-05-25
      • 2019-08-27
      • 2017-06-03
      • 1970-01-01
      相关资源
      最近更新 更多