I have just tried to build Geant4 on win10 with MinGW (MSYS2) and GCC 12.2, and encountered compilation failures. Almost all of these errors come from the exposure of code that should not be compiled on the windows platform (e.g. protected by #ifdef WIN32
or #ifndef WIN32
).
I realized that WIN32
macro definition is missing, however it is used by G4 to distinguish the code routines under the windows platform.
I tried to fix the issue by simply changing some preprocessor macros, and it passed the compilation successfully (with -fpermissive).
The following are the configurations I used and the modifications:
Geant4 version: 11.0.2
Compiler: GCC 12.2.0 (Rev1, Built by MSYS2 project)
Platform: Windows 10 (19044.1949) with MSYS2-20220603 (MinGW64)
CMake configurations:
cmake ../geant4-v11.0.2/ -DCMAKE_CXX_STANDARD=20 -DCMAKE_C_FLAGS="-fpermissive -D_USE_MATH_DEFINES" -DCMAKE_CXX_FLAGS="-fpermissive -D_USE_MATH_DEFINES" -DBUILD_SHARED_LIBS=OFF -DBUILD_STATIC_LIBS=ON -DGEANT4_USE_GDML=ON -DGEANT4_USE_QT=ON -DGEANT4_USE_SYSTEM_ZLIB=ON
Modifications:
In source/externals/g4tools/include/tools/wroot/date
:
25 - #ifdef _MSC_VER
25 + #if defined(_MSC_VER) || defined(__MINGW32__)
In source/global/management/include/G4Timer.hh
:
75 - #ifndef WIN32
75 + #if !(defined(WIN32) || defined(__MINGW32__))
In source/global/management/include/G4SliceTimer.hh
:
42 - #ifndef WIN32
42 + #if !(defined(WIN32) || defined(__MINGW32__))
In source/global/management/src/G4Threading.cc
:
37 - #if defined(WIN32)
37 + #if defined(WIN32) || defined(__MINGW32__)
In source/global/HEPRandom/src/G4UniformRandPool.cc
:
49 - #if defined(WIN32)
49 + #if defined(WIN32) || defined(__MINGW32__)
In source/externals/clhep/include/CLHEP/Utility/thread_local.h
:
10 - #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7) || __clang__ || WIN32
10 + #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7) || __clang__ || defined(WIN32) || defined(__MINGW32__)
In source/processes/hadronic/models/lend/src/MCGIDI_map.cc
:
15 - #ifdef WIN32
15 + #if defined(WIN32) || defined(__MINGW32__)
In source/processes/hadronic/models/lend/src/xDataTOM.cc
:
14 - #ifdef WIN32
14 + #if defined(WIN32) || defined(__MINGW32__)
In source/processes/hadronic/models/lend/src/xDataTOM_importXML.cc
:
14 - #ifdef WIN32
14 + #if defined(WIN32) || defined(__MINGW32__)
In source/interfaces/basic/include/G4UItcsh.hh
:
32 - #ifndef WIN32
32 + #if !(defined(WIN32) || defined(__MINGW32__))
In source/interfaces/basic/src/G4UIExecutive.cc
:
137 - #ifndef WIN32
137 + #if !(defined(WIN32) || defined(__MINGW32__))
I hope this will help.
Sincerely,
SH