Mac OSX 10.15.7 Error: Built target G4physicslists

I’m trying to install Geant4/Geant4Py on my MacBook Pro with the following CMake:

export OPENGL_X11="ON"
export RAYTRACER_X11="ON"
export USE_QT="ON"
export XERCESCPATH=/opt/xerces-c/
export XercesIncludeDir=/opt/xerces-c/include/xercesc/
export XercesRootDir=/opt/xerces-c/lib
export XercesVersion=3.2.3
export boostdir=/usr/local/Cellar/boost/1.76.0
export install_dir=$PWD/../geant4-install
export data_dir=$PWD/../geant4-data
export source_dir=$PWD/../geant4-source
export pyinstallDir=${CONDA_PREFIX}/lib/python${pyMajor}.${pyMinor}/site-packages/

cmake  -DGEANT4_USE_OPENGL_X11=$OPENGL_X11        \
      -DGEANT4_USE_QT=$USE_QT                     \
      -DGEANT4_INSTALL_DATADIR=$data_dir          \
      -DCMAKE_INSTALL_PREFIX=$install_dir         \
      -DCMAKE_INSTALL_PYTHONDIR=$pyinstallDir     \
      -DGEANT4_USE_PYTHON=$G4PYINSTALL            \
      -DCMAKE_PREFIX_PATH=/usr/local/Cellar/qt@5  \
      -DQT_QMAKE_EXECUTABLE=/usr/local/Cellar/qt@5/5.15.2/lib \
      -DGEANT4_BUILD_TLS_MODEL=global-dynamic     \
      -DXercesC_INCLUDE_DIR=$XercesIncludeDir     \
      -DXercesC_LIBRARY=$XercesRootDir            \
      -DXercesC_VERSION=$XercesVersion            \
      -DBOOST_ROOT=/Users/aeglick/Documents/boost_1_77_0 \
      -DBOOST_INCLUDEDIR=/Users/aeglick/Documents/boost_1_77_0                \
      -DBOOST_LIBRARYDIR=/Users/aeglick/Documents/boost_1_77_0/stage/lib \
      -DGEANT4_USE_GDML=ON                        \

which runs to completion no problem. When I try to make it with make -j8 it runs to 94% then returns an error

make: *** [all] Error 2

after building G4physicslists.

What is happening? I don’t get this issue on linux and I’m new to Mac. Thank you!

Could you trace and post the compiler command (and associated error: message) causing the error please?

It looks like this may be the issue.

/Users/aeglick/Geant4.10.7/geant4-source/source/persistency/gdml/include/G4GDMLRead.hh:37:10: fatal error: 'xercesc/parsers/XercesDOMParser.hpp' file not found
#include <xercesc/parsers/XercesDOMParser.hpp>

I tried to include the XercesC library path in CMake as:

export XERCESCPATH=/opt/xerces-c/
export XercesIncludeDir=/opt/xerces-c/include/xercesc/
export XercesRootDir=/opt/xerces-c/lib
export XercesVersion=3.2.3

-DXercesC_INCLUDE_DIR=$XercesIncludeDir     \
-DXercesC_LIBRARY=$XercesRootDir            \
-DXercesC_VERSION=$XercesVersion            \

But it didn’t seem to look there for some reason?

I also want to point out that CMake gave me a flag that it knows where XercesC is located.

-- Found XercesC: /opt/xerces-c/lib (found version "3.2.3")

Part of the issue is that my include path had too much detail in it. The include path should have been:

export XercesIncludeDir=/opt/xerces-c/include/

Now I am getting a new error that states:

ld: can't map file, errno=22 file '/opt/xerces-c/lib/' for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

so there is still something wrong with Xerces-c.

what happens if you skip all the extra detail in your cmake command? I would assume (CMAKE_PREFIX_PATH — CMake 3.21.2 Documentation) that cmake will find, e.g., the include directory if you only provide /opt/xerces-c as CMAKE_PREFIX_PATH

also, notice that you have CMAKE_PREFIX_PATH defined twice in your command.
Does that work as expected? If not, I would give a try to combine into one:


As @weller’s suggested, there’s no need to set the XercesC_... variables if CMAKE_PREFIX_PATH contains the prefix under which it’s installed. These variables are intended for use only when CMake can’t locate the headers/libraries due to unusual install layouts (and these, in general, only occur on very specialised systems).

This is caused by the setting -DXercesC_LIBRARY=/opt/xerces-c/lib, which is telling CMake to link that directory as the library. I.e. it’ll result in the linker running with a flag -l/opt/xerces-c/lib.

1 Like

Thank you @weller @bmorgan. That fixed my issue and I can now run Geant4 and Geant4Py on my Mac!

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