Geant4 code modifications for MSVC++.Net
The Geant4 v5.0 code, as released, does not compile under VC++ .Net, so some
patches are required. These have been archived into a file in .ZIP format and is
available here. This should be unzipped into the
root directory of your Geant4 installation and will overwrite the existing code.
The following files were modified:
The redefinition of min and max is
no longer necessary so the following modifications were made to globals.hh:
- //cng commented out for MSVC++.NET 1/14/03
//#if defined(WIN32) && defined(G4USE_STD_NAMESPACE)
//// For NT with Native STL (used in ISO standard mode)
//// templated functions min and max should be _MIN _MAX
// #define min _MIN
// #define max _MAX
//#endif
//cng
Most of the errors are caused by CLHEP's
redefinition of the abs function. This removes the system definition which
defines abs for complex numbers and results in the following errors:
- Compiling G4VXTRenergyLoss.cc ...
G4VXTRenergyLoss.cc
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(512) :
error C2782: 'T abs(const T &)' : template parameter 'T' is ambiguous
could be 'float' or 'std::complex<_Ty>' with [ _Ty=float ]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(512) :
error C2785: 'T abs(const T &)' and 'float std::abs(const std::complex<_Ty>
&)' have different return types with [ _Ty=float ]
C:/CLHEP\include\CLHEP\config\TemplateFunctions.h(69) : see declaration of
'abs'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(512) :
see declaration of 'std::abs'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(599) :
error C2782: 'T abs(const T &)' : template parameter 'T' is ambiguous
could be 'double' or 'std::complex<_Ty>' with [ _Ty=double ]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(599) :
error C2785: 'T abs(const T &)' and 'double std::abs(const std::complex<_Ty>
&)' have different return types with [ _Ty=double ]C:/CLHEP\include\CLHEP\config\TemplateFunctions.h(69)
: see declaration of 'abs'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(599) :
see declaration of 'std::abs'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(692) :
error C2782: 'T abs(const T &)' : template parameter 'T' is ambiguous
could be 'long double' or 'std::complex<_Ty>' with [ _Ty=long double ]
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(692) :
error C2785: 'T abs(const T &)' and 'long double std::abs(const
std::complex<_Ty> &)' have different return types with [ _Ty=long
double ]
C:/CLHEP\include\CLHEP\config\TemplateFunctions.h(69) : see declaration of
'abs'
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\xcomplex(692) :
see declaration of 'std::abs'
- "Ugly" fix which works:
- Reorder includes in .hh and .cc files to make sure the definition of
complex is included before the include for globals.hh which pulls in the
CLHEP abs definition.
-
- //cng reorder includes to sidestep clhep's redefinition of abs
#include "g4std/complex"
//cng
#include "globals.hh"
#include "templates.hh"
//cng #include "g4std/complex"
Problem encountered in compiling
G4RadioactiveDecay:
- Compiling G4RadioactiveDecay.cc ...
G4RadioactiveDecay.cc
include\G4ITDecayChannel.hh(45) : error C2146: syntax error : missing ')'
before identifier 'G4Ions'
include\G4ITDecayChannel.hh(45) : error C2275: 'G4Ions' : illegal use of
this type as an expression
../../../../../source\particles\management\include\G4Ions.hh(49) : see
declaration of 'G4Ions'
include\G4ITDecayChannel.hh(45) : error C2059: syntax error : ')'
src\G4RadioactiveDecay.cc(1701) : fatal error C1004: unexpected end of file
found
- Problem is the dynamic casting of a base class to its parent in the
constructor method of G4ITDecayChannel.hh:
G4ITDecayChannel (G4int Verbose, const G4ParticleDefinition *theParentNucleus,
G4double theBR) : G4NuclearDecayChannel (IT, Verbose, theParentNucleus,
theBR, 0.0, theParentNucleus->GetBaryonNumber(),
int(theParentNucleus->GetPDGCharge()/eplus), ((const G4Ions*)
theParentNucleus)->GetExcitationEnergy())
Solution is to modify this definition to the following:
G4ITDecayChannel (G4int Verbose, const G4Ions *theParentNucleus, G4double
theBR) :
G4NuclearDecayChannel (IT, Verbose, theParentNucleus, theBR, 0.0,
theParentNucleus->GetBaryonNumber(), int(theParentNucleus->GetPDGCharge()/eplus),
theParentNucleus->GetExcitationEnergy())
Problem encountered in building
G4xcitationHandler:
- Compiling G4ExcitationHandler.cc ...
G4ExcitationHandler.cc
c:\Program Files\Microsoft Visual Studio .NET\Vc7\include\functional(324) :
error C2440: 'initializing' : cannot convert from 'const int' to 'std::binary_function<_Arg1,_Arg2,_Result>::second_argument_type'
with [ _Arg1=G4ReactionProduct *, _Arg2=G4ReactionProduct *, _Result=bool ]
Conversion from integral type to pointer type requires reinterpret_cast,
C-style cast or function-style cast src\G4ExcitationHandler.cc(348) : see
reference to function template instantiation 'std::binder2nd<_Fn2>
std::bind2nd(const _Fn2 &,const int &)' being compiled with [ _Fn2=std::equal_to<G4ReactionProduct
*> ]
- Modify G4ExcitationHandler.cc with following code:
//cng
// theReactionProductVector->erase(G4std::remove_if(theReactionProductVector->begin(),
// theReactionProductVector->end(),
// G4std::bind2nd(G4std::equal_to<G4ReactionProduct*>(),
// 0)),
// theReactionProductVector->end());
G4ReactionProduct* tmp = 0;
theReactionProductVector->erase(G4std::remove_if(theReactionProductVector->begin(),
theReactionProductVector->end(),
G4std::bind2nd(G4std::equal_to<G4ReactionProduct*>(),
tmp)),
theReactionProductVector->end());
i.e. replaced 0, with G4ReactionProduct* tmp = 0;
If you have any comments or suggestions, especially contributions to improve
this set of instructions, please contact me.
Norman Graf