如何在ROOT中编译多个文件

时间:2011-10-22 00:41:49

标签: c++ compilation root-framework

我编写了一个C ++程序(带有main.cpp,以及各种头文件和实现文件),可以在g ++下编译。现在我试图在Cern的ROOT库中编译它,但我不知道如何,因为我知道如何在ROOT中编译文件的唯一方法是使用.L main.cpp

如何在ROOT中包含多个文件?

3 个答案:

答案 0 :(得分:6)

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

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

从单个源文件编译可执行文件“foo”。有关该帮助程序脚本的更多信息,请运行“root-config --help”。

多文件程序/库没有什么特别之处,前提是您提供了指向ROOT库和标题所需的args(并且运行时LDLIBRARY_PATH中提供了lib。)标准C ++指南将在需要时解释该步骤。您也可以放心地将它放入makefile中。

对于我的钱,这比使用CINT解释器中的.L等命令更容易,更可靠。上次我尝试过,ACLiC实际上是针对指定源文件的临时(和损坏的)版本编译的,所以来自编译器的任何错误消息都是无用的!

答案 1 :(得分:3)

我使用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的代码,您需要在顶级项目目录中创建一个“构建”目录,以便您的目录结构如下所示:

proj/
  bin/
  build/
  src/

然后

cd build
cmake ..

您的二进制文件将位于build / bin /目录

希望这有帮助。

答案 2 :(得分:0)

对于我想要的每个文件,我似乎只会.L <filename>,因为.L告诉ROOT“在内存中加载文件的内容”。虽然现在我不太确定加载文件的顺序,因为它们给了我错误。