如何在ROOT下编译多个文件

发布于 2024-12-11 02:15:32 字数 188 浏览 0 评论 0原文

我编写了一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

小耗子 2024-12-18 02:15:32

使用 ROOT 的最可靠方法(至少在历史上和目前)是忽略解释器,而不是进行最简单的探索,并根据 ROOT 库显式编译 C++ 程序。例如,用于

g++ MySource.cc `root-config --libs --cflags` -o foo

从单个源文件编译可执行文件“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

g++ MySource.cc `root-config --libs --cflags` -o foo

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!

音盲 2024-12-18 02:15:32

我使用 CMake 编译基于 ROOT 的项目。
如果您有一个项目目录 proj/ 并且它包含 src/ 和 bin/,则您将需要 3 个 CMakeList.txt 文件,每个目录中一个。

主项目目录中的一个简单示例 CMakeList.txt:

cmake_minimum_required(VERSION 2.6)
project (SOME_PROJ_NAME)
add_subdirectory(src)
add_subdirectory(bin)

src/ 目录是保存 .h 和 .cxx 项目的位置。库文件。示例 CMakeList.txt 文件:

# get all the *.cxx filenames, to compile them into a lib
file(GLOB SOME_PROJ_LIB_SRCS "${PROJECT_SOURCE_DIR}/src/*.cxx")
# include ROOT library and include files
include_directories(/path/to/root/dir/include/dir)
link_directories(/path/to/root/dir/lib/dir)
# and compile src into a library
add_library(Proj_lib_name ${SOME_PROJ_LIB_SRCS})
# here, list the ROOT libraries you require
target_link_libraries(Proj_lib_name dl Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread Gui pthread m)

bin/ 目录是保存应用程序 .cxx 文件的位置,并且它有一个 CMakeList.txt 文件:

include_directories(${PROJECT_SOURCE_DIR}/src)
link_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(/path/to/root/dir/include/dir)
link_directories(/path/to/root/dir/lib/dir)
add_executable(example_app.exe example_app.cxx)
target_link_libraries(example_app.exe Proj_lib_name dl Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread Gui pthread m)

最后,要使用 CMake 编译基于 ROOT 的代码,从源代码中创建一个“build”目录您的顶级项目目录,以便您的目录结构如下所示:

proj/
  bin/
  build/
  src/

然后

cd build
cmake ..

您的二进制文件将位于 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:

cmake_minimum_required(VERSION 2.6)
project (SOME_PROJ_NAME)
add_subdirectory(src)
add_subdirectory(bin)

src/ directory is where you keep your .h and .cxx proj. library files. Example CMakeList.txt file:

# get all the *.cxx filenames, to compile them into a lib
file(GLOB SOME_PROJ_LIB_SRCS "${PROJECT_SOURCE_DIR}/src/*.cxx")
# include ROOT library and include files
include_directories(/path/to/root/dir/include/dir)
link_directories(/path/to/root/dir/lib/dir)
# and compile src into a library
add_library(Proj_lib_name ${SOME_PROJ_LIB_SRCS})
# here, list the ROOT libraries you require
target_link_libraries(Proj_lib_name dl Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread Gui pthread m)

bin/ directory is where you keep your app .cxx files and it has a CMakeList.txt file:

include_directories(${PROJECT_SOURCE_DIR}/src)
link_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(/path/to/root/dir/include/dir)
link_directories(/path/to/root/dir/lib/dir)
add_executable(example_app.exe example_app.cxx)
target_link_libraries(example_app.exe Proj_lib_name dl Core Cint RIO Net Hist Graf Graf3d Gpad Tree Rint Postscript Matrix Physics MathCore Thread Gui pthread m)

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:

proj/
  bin/
  build/
  src/

Then

cd build
cmake ..

Your binaries will be located in build/bin/ directory

Hope this helps.

诗笺 2024-12-18 02:15:32

看来我只需 .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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文