# Check we are where we think we are
if ! test -e $G4INSTALL/source/GNUmakefile
echo "G4INSTALL not set correctly. Please edit setup-geant4 script to fix problem"
if ! test -e $CLHEP_BASE_DIR/include/CLHEP/config/CLHEP.h
echo "CLHEP_BASE_DIR not set correctly. Please edit setup-geant4 script to fix problem"
if [ -z "$PATH" ] ; then
# If we run WIN32-VC* , it also means that it is cygwin
case "$G4SYSTEM" in
export CLHEP_BASE_DIR=`/bin/cygpath -m "$CLHEP_BASE_DIR"`
export G4INSTALL=`/bin/cygpath -m "$G4INSTALL"`
if [ -z "$LIB" ] ; then
if [ -z "$lib" ] ; then
# MacOS X
if [ -z "$DYLD_LIBRARY_PATH" ] ; then
if [ -z "$LD_LIBRARY_PATH" ] ; then
I put this script into /usr/src, then fetched geant4.8.1.p01.gtar.gz and unpacked it into /usr/src/geant4.8.1.p01 . I then typed "cd /usr/src; . setup-geant4.sh" to set the appropriate environment variables. Then I followed the steps outlined in the SLAC documentation and typed "cd geant4.8.1.p01/source; make". After make completed, I tried one of the example programs, following the steps outlined for example A01 in the SLAC tutorial. The program compiled, but I found that it wouldn't produce graphics on an X display. To solve this, I needed to set two more environment variables:
I then went back to the geant4 source directory, did a "make clean" and another "make". Once this had completed, I re-made example A01 and found a different problem. Now I was getting a run-time error that said:
dyld: Symbol not found: __cg_jpeg_resync_to_restart
Referenced from: /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ImageIO.framework/Versions/A/ImageIO
Expected in: /sw/lib/libJPEG.dylib
It turns out that Apple ships a "libJPEG.dylib" with OS X which is completely different from the "libjpeg.dylib" of the same name (modulo case) that fink provides. As you can see above, the setup-geant4.sh script I copied from SLAC adds the directory /sw/lib (where the fink-installed libjpeg.dylib lives) to DYLD_LIBRARY_PATH. The Geant4 program was looking for the Apple-supplied library, but because DYLD_LIBRARY_PATH told it to look in /sw/lib first, it found the fink-supplied file of the "same" name instead. Removing /sw/lib from DYLD_LIBRARY_PATH fixed the problem, and the example ran as expected thereafter.
Note that there is a similar potential name conflict between libGIF.dylib / libgif.dylib. These problems have been noticed by others.
Finally, to set up the environment for compiling Geant4 programs in the future, I copied /usr/src/geant4.8.1.p01 into the master copy of /common/lib/geant4.8.1.p01 and made a symlink from there to /common/lib/geant4. I then arranged to have the following environment variables defined: