如何在ROOT下编译多个文件
我编写了一个 C++ 程序(带有 main.cpp
以及各种头文件和实现文件),可以在 g++ 下正常编译。现在我尝试在 Cern 的 ROOT 库中编译它,但我不知道如何编译,因为我知道如何在 ROOT 中编译文件的唯一方法是使用 .L main.cpp
。
如何在 ROOT 中包含多个文件?
I wrote a C++ program (with a main.cpp
, and various header and implementation files) that compiles fine under g++. Now I am trying to compile it in Cern's ROOT library, but I do not know how to, since the only way I know how to compile files in ROOT is by using .L main.cpp
.
How can I include multiple files in ROOT?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 ROOT 的最可靠方法(至少在历史上和目前)是忽略解释器,而不是进行最简单的探索,并根据 ROOT 库显式编译 C++ 程序。例如,用于
从单个源文件编译可执行文件“foo”。有关该帮助程序脚本的更多信息,请运行“root-config --help”。
多文件程序/库没什么特别的,只要您提供所需的参数来指向 ROOT 库和标头(并且这些库在运行时在 LD_LIBRARY_PATH 中可用。)如果需要,标准 C++ 指南将解释该步骤。您也可以安全地将其放入 makefile 中。
对于我来说,这比在 CINT 解释器中使用 .L 等命令更容易、更可靠。上次我尝试时,ACLiC 实际上是针对指定源文件的临时(且损坏的)版本进行编译,因此来自编译器的任何错误消息几乎毫无用处!
The most reliable way to use ROOT (at least historically and currently) is to ignore the interpreter other than for the simplest explorations and explicitly compile your C++ programs against the ROOT libraries. For example, use
to compile an executable "foo" from a single source file. For more info on that helper script run "root-config --help".
Multi-file programs/libraries are nothing special provided that you supply the required args to point at the ROOT libraries and headers (and that the libs are available in LD_LIBRARY_PATH at runtime.) Standard C++ guides will explain that step if needed. You can safely put this into a makefile, too.
For my money this is both easier and more reliable than using the .L etc. commands in the CINT interpreter. Last time I tried, ACLiC was actually compiling against a temporary (and mangled) version of the specified source file, so any error messages from the compiler were pretty much useless!
我使用 CMake 编译基于 ROOT 的项目。
如果您有一个项目目录 proj/ 并且它包含 src/ 和 bin/,则您将需要 3 个 CMakeList.txt 文件,每个目录中一个。
主项目目录中的一个简单示例 CMakeList.txt:
src/ 目录是保存 .h 和 .cxx 项目的位置。库文件。示例 CMakeList.txt 文件:
bin/ 目录是保存应用程序 .cxx 文件的位置,并且它有一个 CMakeList.txt 文件:
最后,要使用 CMake 编译基于 ROOT 的代码,从源代码中创建一个“build”目录您的顶级项目目录,以便您的目录结构如下所示:
然后
您的二进制文件将位于 build/bin/ 目录中
希望这会有所帮助。
I use CMake to compile my ROOT-based projects.
If you have a project directory proj/ and it contains src/ and bin/, you'll need 3 CMakeList.txt files, one in each directory.
A simple example CMakeList.txt in the main project directory:
src/ directory is where you keep your .h and .cxx proj. library files. Example CMakeList.txt file:
bin/ directory is where you keep your app .cxx files and it has a CMakeList.txt file:
Finally, to compile ROOT-based code with CMake, out of source, you create a "build" dir in your top level project dir, so that your dir structure looks like this:
Then
Your binaries will be located in build/bin/ directory
Hope this helps.
看来我只需
.L
对于每个我想要的文件,因为.L
告诉 ROOT“将文件的内容加载到内存中”。虽然现在我不太确定加载文件的顺序,因为它们给了我错误。It appears that I would simply
.L <filename>
for each file I want, since.L
tells ROOT to "load the contents of file in memory." Though now I am not too sure which order to load the files in, as they are giving me errors.