Hello, My configuration is PBG4 10.4.5 with gcc4.0.1 I want to create shared lib for geant4. I manage to do it, but when I linked my application on them it crash... The crahs reporter show me that : Thread 0 Crashed: 0 libG4event.dylib 0x0656c000 0x656c000 + 0 1 libG4event.dylib 0x0657927c _static_initialization_and_destruction_0(int, int) + 9572 (G4Event.cc:38) 2 libG4event.dylib 0x065793bc _GLOBAL__I_anEventAllocator + 36 (G4Event.cc:112) 3 dyld 0x8fe15984 ImageLoaderMachO::doInitialization(ImageLoader::LinkContext const&) + 820 4 dyld 0x8fe0bca4 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&) + 212 5 dyld 0x8fe0bc34 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&) + 100 6 dyld 0x8fe0bc34 ImageLoader::recursiveInitialization(ImageLoader::LinkContext const&) + 100 7 dyld 0x8fe0d900 ImageLoader::runInitializers(ImageLoader::LinkContext const&) + 92 8 dyld 0x8fe030a0 dyld::initializeMainExecutable() + 92 9 vgm_test.exe 0x00002488 _call_mod_init_funcs + 52 (crt.c:305) 10 vgm_test.exe 0x0000227c _start + 156 (crt.c:226) 11 vgm_test.exe 0x000021dc start + 60 And with gdb it's a little bit better : (gdb) Cannot find bounds of current function (gdb) where #0 0x05bc5000 in anHCoTHAllocator () #1 0x05c8458c in G4Allocator<G4Event>::G4Allocator (this=0x5cc93d8) at /usr/local/geant4/source/global/management/include/G4Allocator.hh:156 #2 0x05bd227c in __static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535) at src/G4Event.cc:38 #3 0x05bd23bc in global constructors keyed to anEventAllocator () at src/G4Event.cc:112 #4 0x8fe15984 in __dyld__ZN16ImageLoaderMachO16doInitializationERKN11ImageLoader11LinkContextE () #5 0x8fe0bca4 in __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextE () #6 0x8fe0bc34 in __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextE () #7 0x8fe0bc34 in __dyld__ZN11ImageLoader23recursiveInitializationERKNS_11LinkContextE () #8 0x8fe0d900 in __dyld__ZN11ImageLoader15runInitializersERKNS_11LinkContextE () #9 0x8fe030a0 in __dyld__ZN4dyld24initializeMainExecutableEv () #10 0x00002488 in _call_mod_init_funcs () at /SourceCache/Csu/Csu-58/crt.c:304 #11 0x0000227c in _start (argc=1, argv=0xbfffd930, envp=0xbfffd938) at /SourceCache/Csu/Csu-58/crt.c:222 #12 0x000021dc in start () Any solutions ???
Functionality of dynamic libraries on the latest versions of MacOSX is currently broken. We are investigating how to overcome the restrictions imposed by the system for static and external symbols, although it is not clear at the moment if all are solvable in a clean way.
The problem is fixed by modifying the compiler options for generating the libraries and linking. The fix is included in the internal tag "config-V08-00-00" and will be part of a next release or patch. You can try it out by cut&paste the text below (after ------) and replace the contents in the file: geant4/config/sys/Darwin-g++.gmk in your setup. ------ # # ------ MacOS-X ------ # MacOS 10.3 gcc-3.3 # MacOS 10.4 gcc-4.0 # # Original author: Helmut Burkhardt - CERN # Revisions: Guy Barrand - LAL # Gabriele Cosmo - CERN # ifeq ($(G4SYSTEM),Darwin-g++) CXX := g++ CXXFLAGS := -Wall -ansi -pedantic -Wno-non-virtual-dtor -Wno-long-long CXXFLAGS += -Wwrite-strings -Wpointer-arith -Woverloaded-virtual -pipe ifdef G4OPTIMISE CXXFLAGS += -O FCFLAGS := -O CCFLAGS := -O else ifdef G4DEBUG CXXFLAGS += -g FCFLAGS := -g CCFLAGS := -g endif endif ifdef G4PROFILE CXXFLAGS += -pg FCFLAGS += -pg CCFLAGS += -pg endif FC := g77 FCFLAGS += -fno-automatic -fno-backslash -fno-second-underscore LDFLAGS += -bind_at_load FCLIBS := -lg2c -lnsl ECHO := /bin/echo -n SHEXT := dylib X11FLAGS := -I/usr/include/X11/extensions -I/usr/include/X11 X11LIBS := -L/usr/X11R6/lib -lXmu -lXt -lXext -lX11 -lXi -lSM -lICE XMFLAGS := -I/sw/include # XMFLAGS := -I/usr/X11R6/include ##### some installations. XMLIBS := -L/sw/lib -lXm -lXpm # XMLIBS := -L/usr/X11R6/lib -lXm -lXpm ##### some installations. DLDLIBS := -ldl ifndef OGLHOME OGLHOME := /usr/X11R6 endif ifndef OGLFLAGS OGLFLAGS := -I$(OGLHOME)/include endif ifndef OGLLIBS OGLLIBS := -L$(OGLHOME)/lib -lGLU -lGL endif define build-granular-shared-lib @libdir=`(cd $(@D);/bin/pwd)`; \ cd $(G4TMPDIR); \ g++ -dynamiclib -single_module -undefined dynamic_lookup \ -o $$libdir/$(@F) $(INTYLIBS) *.o endef define build-global-shared-lib @libdir=`(cd $(@D);/bin/pwd)`; \ cd $(G4TMP)/$(G4SYSTEM); \ g++ -dynamiclib -single_module -undefined dynamic_lookup \ -o $$libdir/$(@F) $(INTYLIBS) $(foreach dir,$(SUBLIBS),$(dir)/*.o); endef endif