use*_*202 5 c++ root-framework c++17
显然,CERN 的“Root”软件(自版本 6.12 起)与 C++17 兼容。然而,我完全无法让它与最新版本(6.20)一起工作,而且我之前发现的关于这个主题的所有问题都是几年前的。
\n有 Root 经验的人知道是否有特定的编译器选项可以让它与 C++17 一起工作吗?
\n尝试编译一个简单的“Hello world”程序时遇到的错误示例:
\n/usr/local/bin/root_v6.20.02/include/ROOT/RStringView.hxx:32:84: error: conflicting declaration of template \xe2\x80\x98template<class _CharT, class _Traits> using basic_string_view = std::experimental::__ROOT::basic_string_view<_CharT, _Traits>\nRun Code Online (Sandbox Code Playgroud)\n/usr/include/c++/7/ext/concurrence.h:53:16: error: \xe2\x80\x98_Lock_policy\xe2\x80\x99 does not name a type \n static const _Lock_policy __default_lock_policy = \n ^~~~~~~~~~~~ \nIn file included from /usr/include/c++/7/iostream:38:0, \n from test.cpp:1: \n/usr/include/c++/7/ext/concurrence.h: In function \xe2\x80\x98void std::__throw_concurrence_lock_error()\xe2\x80\x99: \n/usr/include/c++/7/ext/concurrence.h:102:5: error: \xe2\x80\x98__concurrence_lock_error\xe2\x80\x99 was not declared in this scope \n { _GLIBCXX_THROW_OR_ABORT(__concurrence_lock_error()); } \n ^ \n/usr/include/c++/7/ext/concurrence.h:102:5: note: suggested alternative: \nIn file included from /usr/include/c++/7/memory:74:0, \n from /usr/local/bin/root_v6.20.02/include/ROOT/TypeTraits.hxx:15, \n from /usr/local/bin/root_v6.20.02/include/TString.h:29, \n from /usr/local/bin/root_v6.20.02/include/TNamed.h:26, \n from /usr/local/bin/root_v6.20.02/include/TKey.h:15, \n from /usr/local/bin/root_v6.20.02/include/TBasket.h:28, \n from /usr/local/bin/root_v6.20.02/include/ROOT/TIOFeatures.hxx:14, \n from /usr/local/bin/root_v6.20.02/include/TTree.h:30, \n from /usr/local/bin/root_v6.20.02/include/TNtuple.h:24, \n from test.cpp:2: \n/usr/include/c++/7/ext/concurrence.h:67:9: note: \xe2\x80\x98__gnu_cxx::__concurrence_lock_error\xe2\x80\x99 \n class __concurrence_lock_error : public std::exception \nRun Code Online (Sandbox Code Playgroud)\n我在 Linux 上使用最新版本的 g++ 和 Root,并且 Makefile 中有以下选项:
\nCXX = g++\nCXXFLAGS = -march=native `root-config --cflags --libs` -std=c++17\nLDFLAGS = `root-config --cflags --libs`\nRun Code Online (Sandbox Code Playgroud)\n任何有关可能的解决方法的评论将不胜感激,或者也许我需要在 Makefile 中添加一些附加选项?了解在使用根库时是否建议坚持使用 C++11/14 也会很有帮助。
\n您只能将 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
Run Code Online (Sandbox Code Playgroud)
如果您从源代码编译 root,则CMAKE_CXX_STANDARD=17或cxx17=ON( doc ) 是您想要设置的构建选项,以使用 c++17 编译 root 并在所有下游项目中使用 c++17。
如果您使用 root 的二进制安装,则需要由提供构建的人来完成切换。