Dear Experts,
I am actually new to PyTorch. I would like to use the concept of RDataFrame from ROOT software together with PyTorch C++ frontend, but I faced problems in compiling my program, you see here a simplified version of the Program.cxx and CMakeLists.txt
#include <iostream>
#include <torch/torch.h>
#include "ROOT/RDataFrame.hxx"
#include "ROOT/RVec.hxx"
#include "ROOT/RDF/RInterface.hxx"
#include "TFile.h"
int main() {
TFile *f = new TFile("file.root");
ROOT::RDataFrame df("tree", "file.root");
//f->ls();
torch::Tensor tensor = torch::rand({2, 3});
std::cout << std::endl << tensor << std::endl;
return 0;
}
and CMakeLists.txt
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(Program)
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
find_package(Torch REQUIRED)
find_package(ROOT REQUIRED)
include(${ROOT_USE_FILE})
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(Program Program.cxx)
target_link_libraries(Program "${ROOT_LIBRARIES}")
target_link_libraries(Program "${TORCH_LIBRARIES}")
set_property(TARGET Program PROPERTY CXX_STANDARD 11)
and I always get this error:
/usr/bin/ld: CMakeFiles/Program.dir/Program.cxx.o: in function `main':
program.cxx:(.text+0x134): undefined reference to `ROOT::RDataFrame::RDataFrame(std::experimental::__ROOT::basic_string_view<char, std::char_traits<char> >, std::experimental::__ROOT::basic_string_view<char, std::char_traits<char> >, std::vector<std::string, std::allocator<std::string> > const&)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/Program.dir/build.make:105: Program] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/Program.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
NOTE: It compiles and run correctly when I comment the line ROOT::RDataFrame df("tree", "file.root");
. Also when I disable Torch (see example below) and compile without it it compiles and run correctly. So it seems to me that there is a conflict between Torch and ROOTDataframe (specifically) from ROOT.
CMakeLists.txt/Program without Torch:
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
project(Program)
list(APPEND CMAKE_PREFIX_PATH $ENV{ROOTSYS})
find_package(ROOT REQUIRED)
include(${ROOT_USE_FILE})
#include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
add_executable(Program Program.cxx)
target_link_libraries(Program "${ROOT_LIBRARIES}")
set_property(TARGET Program PROPERTY CXX_STANDARD 11)
#include <iostream>
#include "ROOT/RDataFrame.hxx"
#include "ROOT/RVec.hxx"
#include "ROOT/RDF/RInterface.hxx"
#include "TFile.h"
int main() {
TFile *f = new TFile("file.root");
ROOT::RDataFrame df("tree", "file.root");
//f->ls();
return 0;
}
Any suggestions how to solve this problem?!
Thank you all