I have error whenever I want to compile simplest code for detector construction. Undefined reference to MyDetectorConstruction::MyDetectorConstruction()

make
[ 50%] Building CXX object CMakeFiles/practice.dir/practice.cc.o
[100%] Linking CXX executable practice
/usr/bin/ld: CMakeFiles/practice.dir/practice.cc.o: in function main': practice.cc:(.text+0x75): undefined reference to MyDetectorConstruction::MyDetectorConstruction()’
/usr/bin/ld: practice.cc:(.text+0xab): undefined reference to `MyPhysicsList::MyPhysicsList()’
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/practice.dir/build.make:142: practice] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/practice.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

1 Like

Do you have classes named MyDetectorConstruction and MyPhysicsList in your sources? If you do, do you have the .cc and .hh files listed in your CMakeLists.txt file? If the sources aren’t listed there, then they won’t be compiled.

Hi @Rajka_Pejanovic
did your error solved?? I am getting same error ,tried every method mentioned but no success