Geant4 with g4py binding in MacOS

Dear experts,

In a previous post #3642 a recipe to build Geant4 via brew has been discussed. The local formula works fine and Geant4 is properly built.

OTOH, that formula doesn’t include the Geant4 python bindings, which I tried to include by adding the flags “-DGEANT4_USE_PYTHON=ON”. Surprisingly, it does not work as expected and I get several errors similar to the one below:

/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:329:9: error: no
  member named 'isunordered' in the global namespace
using ::isunordered;
13 errors generated.

It seems I have a broken link within the clang toolchain, maybe because I’m not using Xcode but only Command Line Tools.

Partial solution: the same issue is seen when I try to compile the examples in Geant4 without g4py, which can be easily cured with the following flag within the cmake command:


Building from source: I left brew behind and tried to build geant4 from source using the DCMAKE_OSX_SYSROOT flag, but unfortunately this flag does not solve the issue in building Geant4 with g4py (either brew or from source, but works for examples). The information present in the documentation (link) seems to not be enough to fix the issue from my side.

Is there a proper way to pass the DCMAKE_OSX_SYSROOT flag to build Geant4 with g4py?

I did a small cpp code with only

#include <cmath>

and compiled it with:

clang -v -x c++ -std=c++11 -stdlib=libc++ -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/ -isystem /Library/Developer/CommandLineTools/usr/include -c cmath-bug.cpp 

and it works fine (but does not work without the -isystem and -isysroot flags). Possibly I have some weird config in my MacOS system that Geant4 cmake is not getting the proper c++ headers, so any help is welcome.

Cheers, Gustavo

This requires Python 3, plus Boost with Python3 support. If you want Geant4 built in Multithreaded mode with Python, this will also require the options:


Hi @weller,

Thanks for the quick reply.

I followed that post and I do have boost-python3 and set those flags either in the brew formula or building from source. It seems that my toolchain is looking for math.h at /usr/local/include instead of /Library/Developer/CommandLineTools/:

$ clang -Wp,-v -E -
clang -cc1 version 12.0.0 (clang-1200.0.32.29) default target x86_64-apple- darwin19.6.0
ignoring nonexistent directory 
ignoring nonexistent directory"/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/Library/Frameworks"
#include "..." search starts here:
#include <...> search starts here:
/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks (framework directory)
End of search list.

I cannot find a proper solution for this case after searching in several places.

Since we are in this topic: is Python@3.9 supported or should I go with Python@3.7?

$ brew config
HOMEBREW_VERSION: 3.1.3-93-g3594283
HEAD: 35942830fbb373f62aba0044f9ae640788e07be1
Last commit: 2 days ago
Core tap ORIGIN:
Core tap HEAD: 0e08c8db106261916201ca1412963c8b22b7c68a
Core tap last commit: 2 days ago
Core tap branch: master
HOMEBREW_DISPLAY: /private/tmp/
Homebrew Ruby: 2.6.3 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.3_2/bin/ruby
CPU: quad-core 64-bit haswell
Clang: 12.0 build 1200
Git: 2.31.1 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 10.15.7-x86_64
Xcode: N/A

Cheers, Gustavo

did you install OS updates recently? or xcode updates? you could try to reinstall CommandLineTools

sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install

Sure, more than once :slight_smile:

I removed Xcode last month, but haven’t seen any issue until trying to install this python binding. Apart of avoiding install Xcode again, I believe there is a clever way to compile Geant4 in a smart way with CommandLineTools…

Note: I do have a gcc installed via brew. I’m planning to remove it as a cross-check, but it’s linked to other formulas so I have to plan it first.

I do have this folder in my machine, but indeed I have xcode installed… maybe the commandlinetools simply need this to work properly

I don’t think so, because I can compile the examples using that cmake flag. I believe it’s just a matter of linking it properly for building Geant4 with g4py.

Given that I have a gcc installed via brew, I suspect that boost-python3 may be linked to this gcc instead of Command Line Tools.

Just to give a more clear view, my compilation process crashes at 95% when compiling

[ 95%] Building CXX object environments/g4py/source/global/CMakeFiles/pyG4global.dir/

In file included from $HOME/Downloads/geant4.10.07.p01/environments/g4py/source/global/

In file included from $HOME/Downloads/geant4.10.07.p01/environments/g4py/source/global/G4PyCoutDestination.hh:34:

In file included from $HOME/Downloads/geant4.10.07.p01/source/global/management/include/G4coutDestination.hh:42:

In file included from $HOME/Downloads/geant4.10.07.p01/source/global/management/include/globals.hh:35:

In file included from $HOME/Downloads/geant4.10.07.p01/source/global/management/include/G4ios.hh:35:

In file included from $HOME/Downloads/geant4.10.07.p01/source/global/management/include/G4Types.hh:74:

In file included from /Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/complex:245:

/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/cmath:317:9: error: no

member named 'signbit' in the global namespace

using ::signbit;

sorry, can’t be of any help then :frowning:

fyi: I have compiled g4 with python bindings using the brew formula from the other thread without any issues, just added

depends_on "boost-python3"



at the obvious positions and a quick

brew reinstall --build-from-source geant4

Thanks for checking. I still get the same error by using boost-python3 in brew. There should be a way to properly compile it without using ~30GB of disk space just to install Xcode.

I’ll update this thread when I find a solution.