如何修复 ROOT 错误:'gROOT' was not declared in this scope
问题:
编译基于 ROOT 的 C++ 程序时,你收到如下错误消息:
groot_not_declared_error.txt
main.cpp: In member function ‘int main()’:
main.cpp:26:22: error: ‘gROOT’ was not declared in this scope; did you mean ‘ROOT’?
26 | auto cdpad = gROOT->GetSelectedPad();解决方案:
错误消息有点误导。问题是 gROOT 对象在全局作用域中不可用。你需要包含 ROOT 头文件 TROOT.h 才能访问它。在源文件顶部包含以下行:
include_troot.cpp
#include <TROOT.h>If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow