CMake File issue

Hi, I am running a GEANT4 program that calls upon ROOT files and headers. In the cmake file I have included ROOT directories :

# Locate sources and headers for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include
                    ${Geant4_INCLUDE_DIR}
	            ${ROOT_INCLUDE_DIRS})  		
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)

However, when I run the CMake file I run into these errors :

/usr/bin/ld: CMakeFiles/FCP_Simulation.dir/src/ActionInitialization.cc.o: in function `_GLOBAL__sub_I_ActionInitialization.cc':
ActionInitialization.cc:(.text.startup+0x44): undefined reference to `TVersionCheck::TVersionCheck(int)'
/usr/bin/ld: CMakeFiles/FCP_Simulation.dir/src/EventAction.cc.o: in function `EventAction::EventAction(RunAction*)':
EventAction.cc:(.text+0x229): undefined reference to `TStorage::ObjectAlloc(unsigned long)'
/usr/bin/ld: EventAction.cc:(.text+0x24f): undefined reference to `TFile::TFile(char const*, char const*, char const*, int)'
/usr/bin/ld: EventAction.cc:(.text+0x258): undefined reference to `TDirectory::CurrentDirectory()'
/usr/bin/ld: EventAction.cc:(.text+0x265): undefined reference to `TStorage::ObjectAlloc(unsigned long)'
/usr/bin/ld: EventAction.cc:(.text+0x286): undefined reference to `TTree::TTree(char const*, char const*, int, TDirectory*)'
/usr/bin/ld: EventAction.cc:(.text+0x2aa): undefined reference to `TTree::Branch(char const*, void*, char const*, int)'
/usr/bin/ld: CMakeFiles/FCP_Simulation.dir/src/EventAction.cc.o: in function `_GLOBAL__sub_I_EventAction.cc':
EventAction.cc:(.text.startup+0x38): undefined reference to `TVersionCheck::TVersionCheck(int)'
/usr/bin/ld: CMakeFiles/FCP_Simulation.dir/src/EventAction.cc.o: in function `EventAction::EventAction(RunAction*) [clone .cold]':
EventAction.cc:(.text.unlikely+0x4): undefined reference to `TObject::operator delete(void*)'
/usr/bin/ld: EventAction.cc:(.text.unlikely+0x1c): undefined reference to `TObject::operator delete(void*)'
/usr/bin/ld: CMakeFiles/FCP_Simulation.dir/src/SteppingAction.cc.o: in function `_GLOBAL__sub_I_SteppingAction.cc':
SteppingAction.cc:(.text.startup+0x38): undefined reference to `TVersionCheck::TVersionCheck(int)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/FCP_Simulation.dir/build.make:400: FCP_Simulation] Error 1
make[1]: *** [CMakeFiles/Makefile2:76: CMakeFiles/FCP_Simulation.dir/all] Error 2
make: *** [Makefile:130: all] Error 2

I have asked previously in the ROOT forum but I have been directed here regarding including the missing ROOT Libraries.

Any help is greatly appreciated!

Can you include your entire CMake file so that we can provide better advice?

Hi, see below cmake file

#---------------`-------------------------------------------------------------
# Setup the project
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(FCP_Simulation)

#----------------------------------------------------------------------------
# Find Geant4 package, activating all available UI and Vis drivers by default
# You can set WITH_GEANT4_UIVIS to OFF via the command line or ccmake/cmake-gui
# to build a batch mode only executable
#
option(WITH_GEANT4_UIVIS "Build example with Geant4 UI and Vis drivers" ON)
if(WITH_GEANT4_UIVIS)
  find_package(Geant4 REQUIRED ui_all vis_all)
else()
  find_package(Geant4 REQUIRED)
endif()

#----------------------------------------------------------------------------
# Setup Geant4 include directories and compile definitions
#
include(${Geant4_USE_FILE})

#----------------------------------------------------------------------------
# Find ROOT (required package)
#
find_package(ROOT QUIET)
if(NOT ROOT_FOUND)
  message(STATUS "G4 Examples: ROOT package not found")
  return()
endif()

#----------------------------------------------------------------------------
# Locate sources and headers for this project
#
include_directories(${PROJECT_SOURCE_DIR}/include
                    ${Geant4_INCLUDE_DIR}
	            ${ROOT_INCLUDE_DIRS})  		
file(GLOB sources ${PROJECT_SOURCE_DIR}/src/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/include/*.hh)

#----------------------------------------------------------------------------
# Add the executable, and link it to the Geant4 libraries
#
add_executable(FCP_Simulation FCP_Simulation.cc ${sources} ${headers})
target_link_libraries(FCP_Simulation ${Geant4_LIBRARIES})

Make sure to link your executable to root itself:

target_link_libraries(FCP_Simulation ${Geant4_LIBRARIES} ${ROOT_LIBRARIES})

Thank you ! It works now !

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.