函数未定义的引用问题
PhysicsList.cc文件里面的 fPMessenger = new PhysicsListMessenger(this);报错PhysicsList.cc:(.text+0x1d9):对‘PhysicsListMessenger::PhysicsListMessenger(PhysicsList*)’未定义的引用
PhysicsList.cc文件
#include "PhysicsList.hh"
#include "G4HadronPhysicsQGSP_BIC_HP.hh"
#include "G4EmLivermorePhysics.hh"
#include "G4EmStandardPhysics.hh"
#include "G4RadioactiveDecayPhysics.hh"
#include "G4IonElasticPhysics.hh"
#include "G4EmStandardPhysics_option4.hh"
#include "G4EmPenelopePhysics.hh"
#include "G4EmExtraPhysics.hh"
#include "G4DecayPhysics.hh"
#include "G4HadronElasticPhysicsHP.hh"
#include "G4HadronPhysicsFTFP_BERT_HP.hh"
#include "G4StoppingPhysics.hh"
#include "G4OpticalPhysics.hh"
#include "G4IonPhysics.hh"
#include <stdio.h>
#include "PhysicsListMessenger.hh"
#include "G4EmLowEPPhysics.hh"
#include "G4SystemOfUnits.hh"
#include "G4LossTableManager.hh"
using namespace std;
PhysicsList::PhysicsList() : G4VModularPhysicsList(),
fUseMIFlag(true),
fPMessenger(0)
{
G4LossTableManager::Instance();
// set default cuts value
defaultCutValue = 1 * eV;
// define the messenger
fPMessenger = new PhysicsListMessenger(this);
PhysicsList.hh
#include "G4VModularPhysicsList.hh"
class G4VPhysicsConstructor;
class PhysicsListMessenger;
/// Modular physics list
///
/// It includes the folowing physics builders
/// - G4DecayPhysics
/// - G4RadioactiveDecayPhysics
/// - G4EmStandardPhysics
class PhysicsList: public G4VModularPhysicsList
{
public:
PhysicsList();
virtual ~PhysicsList();
virtual void SetCuts();
//for the Messenger
void SetDefaultCutsValue(G4double);
void SelectPhysicsList(const G4String& name);
void SetUseMIFlag(G4bool val){fUseMIFlag = val;};
G4bool GetUseMIFlag(){return fUseMIFlag;};
private:
PhysicsList & operator = (const PhysicsList &right);
PhysicsList(const PhysicsList&);
G4VPhysicsConstructor* fParticleList;
G4VPhysicsConstructor* fEmPhysicsList;
G4bool fUseMIFlag;
PhysicsListMessenger* fPMessenger;
};
#endif
PhysicsListMessenger .hh
#ifndef PhysicsListMessenger_h
#define PhysicsListMessenger_h 1
#include "globals.hh"
#include "G4UImessenger.hh"
class PhysicsList;
class G4UIdirectory;
class G4UIcmdWithAnInteger;
class G4UIcmdWithADoubleAndUnit;
class G4UIcmdWithAString;
class G4UIcmdWithABool;
class PhysicsListMessenger : public G4UImessenger
{
public:
PhysicsListMessenger(PhysicsList*);
virtual ~PhysicsListMessenger();
virtual void SetNewValue(G4UIcommand*, G4String);
private:
PhysicsList* fPhysicsList;
G4UIdirectory* fPhysDir;
G4UIcmdWithADoubleAndUnit* fCutsCmd;
G4UIcmdWithAString* fListCmd;
G4UIcmdWithABool* fUseMIFlagCmd;
};
#endif
PhysicsListMessenger。cc
#include "PhysicsListMessenger.hh"
#include "PhysicsList.hh"
#include "G4UIdirectory.hh"
#include "G4UIcmdWithAnInteger.hh"
#include "G4UIcmdWithADoubleAndUnit.hh"
#include "G4UIcmdWithAString.hh"
#include "G4UIcmdWithABool.hh"
//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
PhysicsListMessenger::PhysicsListMessenger(PhysicsList* pPhys):
G4UImessenger(),
fPhysicsList(pPhys)
{
fPhysDir = new G4UIdirectory("/phys/");
fPhysDir->SetGuidance("PhysicsList control");
fCutsCmd = new G4UIcmdWithADoubleAndUnit("/phys/setCuts",this);
fCutsCmd->SetGuidance("set cuts");
fCutsCmd->SetParameterName("cuts",false);
fCutsCmd->SetUnitCategory("Length");
fCutsCmd->SetRange("cuts>0.");
fCutsCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
}
这个错误通常是由于未正确链接PhysicsListMessenger类的构造函数引起的。首先,确保PhysicsListMessenger类的构造函数在PhysicsListMessenger.cc文件中被正确实现。然后,在编译和链接代码时,确保将PhysicsListMessenger.cc文件包含在编译过程中,以便正确链接到PhysicsList.cc文件。
另外,建议检查Makefile或项目配置文件,确保PhysicsListMessenger.cc文件被正确包含在编译过程中。如果Makefile或项目配置文件正确配置了PhysicsListMessenger.cc文件,但仍然出现该错误,可能是由于其他编译选项或依赖关系导致的问题。
页:
[1]