Having Program Compilation Issues in Python and C++

I’m a final year MPhys student currently doing a project to bridge Mitsuba 3 and Geant4 at the University of Manchester, and I’m having a few issues trying to compile a working program (I’m following the Physics Matters tutorials at https://www.youtube.com/playlist?list=PLLybgCU6QCGWgzNYOV0SKen9vqg4KXeVL , as reccommended by my supervisor) and I’ve tried three different methods:

  1. Firstly, I tried to create a program using Python as I am far more proficient at using it. I installed Geant 4 11.0.0 through the anaconda-forge package (using G4Py bindings) on Ubuntu 24.04.3 LTS via Windows Subsystem for Linux and I am using Spyder as my IDE. The module imports without any issue and I’ve been able to translate the bindings from the tutorial’s C++ source, however, I run into an issue when I try to run the program when using the PVPlacement method:

It seems strange, given that the RotationMatrix and ThreeVector classes inherit from the given base classes in CLHEP, none of the other methods reliant on pointers have failed and there doesn’t appear to be a CLHEP module to import.

  1. After this, I tried to use C++ on Windows 10, using MinGWx64 g++, VSCode 1.84.2 and Geant4 11.0.1 as installed by the binary installer. The headers and library were able to be linked successfully, but upon compilation (both via the debugger and Windows Terminal), I get reference errors located inside the headers, for instance:
C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/12.1.0/../../../../x86_64-w64-mingw32/bin/ld.exe: C:\Users\james\AppData\Local\Temp\cccXta5R.o: in function `G4VisExecutive::~G4VisExecutive()':
D:/Geant4-11.0.1/include/Geant4/G4VisExecutive.hh:119: undefined reference to `G4VisManager::~G4VisManager()'
  1. I also tried to use CMake 3.28.0-rc5 to compile, the Makefile was able to generate with no issues but attempting to compile the Makefile throws these errors:
g++.exe: error: unrecognized command-line option '-GR'; did you mean '-R'?
g++.exe: error: unrecognized command-line option '-EHsc'
g++.exe: error: unrecognized command-line option '-Zm200'

If anyone has a known fix or solution to any of these issues, it would be greatly appreciated.

The conda package should be fine for programming in C++, but the G4Py bindings are only partial so we’d strongly recommend only using the C++ interface. You could also try GitHub - HaarigerHarald/geant4_pybind: Alternative Python bindings for Geant4, but given what your project is trying to do, the C++ interface will likely be more useful.

Geant4 is not testing nor supported on MinGW, but Visual Studio Community should work fine (as documented in the Install Guide: Building and Installing from Source — Geant4 Installation Guide 11.1 documentation

One further option is the Geant4 VM: First steps with Geant4 (27-31 March 2023): Geant4 Virtual Machine · Indico

Hi there, I was able to get a working program to compile via my C++ installation on Windows - I noticed that the “undefined reference to class::method()” issue can occur when the compiler sees a multiple or cyclical definition. It seems to happen because there’s many files that g++ tries to compile at once when included, so inclding the “-c” flag at compilation allows everything to compile separately before linking to my main source file, which fixes the compilation issue.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.