Error while compiling simple code for detector construction: undefined reference to `MyDetectorConstruction::DefineMaterials()

I have this error while adding the sensitive volume to the detector:

/usr/bin/ld: CMakeFiles/sim.dir/construction.cc.o: in function MyDetectorConstruction::MyDetectorConstruction()': construction.cc:(.text+0x37): undefined reference to MyDetectorConstruction::DefineMaterials()’
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/sim.dir/build.make:204: sim] Error 1
make[1]: *** [CMakeFiles/Makefile2:104: CMakeFiles/sim.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

Can someone please help me remove it?

It looks as if you have declared a function and forgot to include the .cc file with its implementation in the CMake project.

This is my CMakeLists.txt file

cmake_minimum_required(VERSION 2.6 FATAL_ERROR)

project(Simulation)

find_package(Geant4 REQUIRED ui_all vis_all)

include(${Geant4_USE_FILE})

file(GLOB sources ${PROJECT_SOURCE_DIR}/*.cc)
file(GLOB headers ${PROJECT_SOURCE_DIR}/*.hh)

add_executable(sim sim.cc ${sources} ${headers})
target_link_libraries(sim ${Geant4_LIBRARIES})

file(GLOB MACRO_FILES
  "*.mac"
)
file(COPY ${MACRO_FILES} DESTINATION ${PROJECT_BINARY_DIR})

file(GLOB DATA_FILES
  "*.dat"
)
file(COPY ${DATA_FILES} DESTINATION ${PROJECT_BINARY_DIR})

add_custom_target(Simulation DEPENDS sim)

I think I added all the .cc and .hh files.

Then check you have re-run cmake and also check in which file you implemented the method.

@Lauri122 did you solve error???i am also getting this error