Hi,
I’m trying to integrate TUnfold into a cmake project and I am seeing what I assume to be linker errors, though I don’t know how to resolve this. I built ROOT myself and I can run the TUnfold examples but when I try to run the same functions inside my cmake program it doesn’t find the necessary libraries. I know that the version of ROOT that I am running already has TUnfold integrated into it so I’m not sure if I have to make a shared library myself as indicated in the README.
My cmake file is as follows:
cmake_minimum_required(VERSION 3.11.0 FATAL_ERROR)
project(WWbbPlotting LANGUAGES CXX)
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules ${CMAKE_MODULE_PATH})
include(GNUInstallDirs)
include(CheckCXXCompilerFlag)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(QUALITY_CXX_FLAGS_TO_CHECK "-g" "-O2" "-pedantic" "-Werror" "-Wall" "-Wextra" "-Wno-unused-parameter")
find_package(ROOT REQUIRED COMPONENTS Core RIO Tree Physics Hist)
#find_package(ROOT 6.24 CONFIG REQUIRED Core RIO Tree Physics Hist)
file( GLOB LIBPLOTTING_SRC "${PROJECT_SOURCE_DIR}/Root/*.cxx" )
add_library( LIBPLOTTING SHARED ${LIBPLOTTING_SRC} )
target_include_directories( LIBPLOTTING PRIVATE ${PROJECT_SOURCE_DIR}/WWbbPlotting ${ROOT_INCLUDE_DIRS} )
add_executable(WWbbPlotting src/WWbbPlotting.cxx)
target_include_directories( WWbbPlotting PRIVATE ${PROJECT_SOURCE_DIR}/WWbbPlotting ${ROOT_INCLUDE_DIRS} )
message(STATUS "ROOT INCLUDE DIRS = ${ROOT_INCLUDE_DIRS}")
set_target_properties( WWbbPlotting PROPERTIES LINKER_LANGUAGE CXX)
set_target_properties( LIBPLOTTING PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries( LIBPLOTTING ${$ROOT_LIBRARIES} stdc++fs )
target_link_libraries( WWbbPlotting LIBPLOTTING ${ROOT_LIBRARIES})
install (TARGETS WWbbPlotting DESTINATION lib)
install (DIRECTORY "${PROJECT_SOURCE_DIR}/WWbbPlotting" DESTINATION include FILES_MATCHING PATTERN "*.h")
And my main function only contains a single line where I am trying to access the default TUnfoldDensity constructor:
#include <iostream>
#include <TUnfoldDensity.h>
int main(){
TUnfoldDensity* unfold = new TUnfoldDensity();
}
But I get the following compilation error:
/usr/bin/ld: CMakeFiles/WWbbPlotting.dir/src/WWbbPlotting.cxx.o: in function `main':
WWbbPlotting.cxx:(.text+0x20): undefined reference to `TUnfoldDensity::TUnfoldDensity()'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/WWbbPlotting.dir/build.make:104: WWbbPlotting] Error 1
make[1]: *** [CMakeFiles/Makefile2:78: CMakeFiles/WWbbPlotting.dir/all] Error 2
make: *** [Makefile:130: all] Error 2
This is strange because I can include other root libraries just fine but TUnfold isn’t found by the linker. Any help is appreciated. Thanks!
_ROOT Version: 6.24/06
Platform: Ubuntu 20.04
Compiler: Not Provided