簡體   English   中英

如何將 CERN Root 與 C++17 一起使用?

[英]how can I use CERN Root with C++17?

顯然,CERN 的“Root”軟件與 C++17 兼容(從 6.12 版開始)。 但是,我完全無法讓它與最新版本(6.20)一起使用,而且我在這個主題上發現的所有以前的問題都是幾年前的。

有 Root 經驗的人是否知道是否有特定的編譯器選項可以使其與 C++17 一起使用?


我在嘗試編譯一個簡單的“Hello world”程序時遇到的錯誤示例:

  • 以下是(我認為)由於“TFile.h”header 隱式加載“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 也會很有幫助。

您只能將 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 的二進制安裝,則該切換需要由提供構建的任何人完成。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM