ROOT based project with CMake - clarification

Dear experts,

I need some clarification on how to compile a ROOT based project with CMake.
See for example the attachment, error could be reproduced by running . scripts/

I am using v6.05/02 compiled on OS X with CMake.
The compilation fails at the time of dictionary generation with the following error:

Undefined symbols for architecture x86_64:
  "Selector::Class()", referenced from:
      Selector::IsA() const in Selector.o
      Selector::ShowMembers(TMemberInspector&) const in Selector.o
  "Selector::Streamer(TBuffer&)", referenced from:
      vtable for Selector in Selector.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

What am I missing?
test.tar.gz (2.21 KB)

The CMakeList.txt file like this should work:

# CMakeLists.txt for D0Lifetime module. It creates a library with dictionary and a main program
cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
set(PACKAGE Test)

# You need to tell CMake where to find the ROOT installation. This can be done in a number of ways:
#   - ROOT built with classic configure/make use the provided $ROOTSYS/etc/cmake/FindROOT.cmake
#   - ROOT built with CMake. Add in CMAKE_PREFIX_PATH the installation prefix for ROOT

#---Locate the ROOT package and defines a number of variables (e.g. ROOT_INCLUDE_DIRS)
find_package(ROOT REQUIRED COMPONENTS Graf3d Graf Gpad MathCore RIO Hist Tree Net Thread)

#---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)

#--- Add dependency
#set( DEPENDENCIES Utilities)
#foreach( comp ${DEPENDENCIES} )
#	 include_directories(${CMAKE_SOURCE_DIR}/${comp}/include)
#	 add_subdirectory(${CMAKE_SOURCE_DIR}/build/${comp})
#endforeach( comp )

include_directories(include ${ROOT_INCLUDE_DIRS})
#--- Define the headers list
set(headers include/Selector.h)

#--- Define the source list
set(src_files Selector.cpp)
foreach(src_file ${src_files})
   set(sources ${sources} src/${src_file})

#---Create a shared library with geneated dictionary
add_library(${PACKAGE} SHARED ${sources} G__${PACKAGE}.cxx)
target_link_libraries(${PACKAGE} ${ROOT_LIBRARIES})# ${DEPENDENCIES})

#---Create an executable
#add_executable(Test ${CMAKE_SOURCE_DIR}/main/
#target_link_libraries(Test ${PACKAGE})

It is not nice that you need to specify “include/Selector.h” and “include/${PACKAGE}Dict.h” while at the same time the include_directories() is already including ‘include’. I’ll make necessary fixes to avoid it in the next release.

Hi Pere,

Many thanks for your answer. Compilation now works.
I guess that the problem was that I was including by mistake wrong CMake functions from $ENV{ROOTSYS}/etc/cmake with this line (now commented):



When ROOT is built with cmake, the file ROOTConfig.cmake is created, which replaces the module in $ROOTSYS/etc/cmake/FindROOT.cmake. I would probably make sure that this one does not get installed to avoid confusion.