# Undefined reference to \`MySensitiveDetector::MySensitiveDetector(G4String)'

**URL:** <https://geant4-forum.web.cern.ch/t/undefined-reference-to-mysensitivedetector-mysensitivedetector-g4string/10265>\
**Category:** Geometry, Fields and Transportation\
**Created:** [March 17, 2023, 2:09pm UTC](https://geant4-forum.web.cern.ch/t/undefined-reference-to-mysensitivedetector-mysensitivedetector-g4string/10265 "2023-03-17T14:09:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lauri122](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/lauri122/32/5971_2.png) [@Lauri122](https://geant4-forum.web.cern.ch/u/Lauri122)\
**Post date:** [March 17, 2023, 2:09pm UTC](https://geant4-forum.web.cern.ch/t/undefined-reference-to-mysensitivedetector-mysensitivedetector-g4string/10265/1 "2023-03-17T14:09:14Z")

</div>

Hello, I am a beginner trying to learn Geant4.  
I have the following error, don’t quite understand why. Can someone please help?

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

Relevant part of code in contruction.cc

```auto
void MyDetectorConstruction::ConstructSDandField()
{
  MySensitiveDetector *sensDet = new MySensitiveDetector("SensitiveDetector");
  
  
  logicDetector->SetSensitiveDetector(sensDet);

}

```

Here is the header file contruction.hh:

```auto
#ifndef CONSTRUCTION_HH
#define CONSTRUCTION_HH
#include "G4SystemOfUnits.hh"
#include "G4VUserDetectorConstruction.hh"
#include "G4VPhysicalVolume.hh"
#include "G4LogicalVolume.hh"
#include "G4Box.hh"
#include "G4PVPlacement.hh"
#include "G4NistManager.hh"

#include "detector.hh"

class MyDetectorConstruction : public G4VUserDetectorConstruction
{
  
public:
    MyDetectorConstruction();
    ~MyDetectorConstruction();
    
    virtual G4VPhysicalVolume *Construct();
    
private:
    G4LogicalVolume *logicDetector;
    virtual void ConstructSDandField();

};

#endif 

```

---

<div class="post-metadata">

**Author:** ![weller](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/weller/32/3357_2.png) [@weller](https://geant4-forum.web.cern.ch/u/weller)\
**Post date:** [March 17, 2023, 3:45pm UTC](https://geant4-forum.web.cern.ch/t/undefined-reference-to-mysensitivedetector-mysensitivedetector-g4string/10265/2 "2023-03-17T15:45:01Z")

</div>

I can recommend the references for introductory material on c++ in this post:

> [@Beginner at geant4](https://geant4-forum.web.cern.ch/t/beginner-at-geant4/9370/2):
>
> Hi, A good first step is to copy one of the basic examples and just play with it. Change an input file according to what the README says you can do, run it and see how the output changes. When you understand (roughly) how it works, modify the code to do something different that is of interest to you, recompile it and run it. For example, change the geometry and/or materials and see how the outputs change. Modify the readout mechanism, be it in stepping action or a sensitive detector to output a…

seems you are missing a

```auto
public:
    MyDetectorConstruction(G4String);

```

entry (plus maybe implementation).
