./exampleB1: symbol lookup error: ./exampleB1: undefined symbol: G4cout

Hello, I am a newbie with Geant4 and I came across this interesting error trying to run exampleB1. I am using Ubuntu 18.04.1 and Geant4.10.04.p2, and when I compile my executable and run it, the following error comes up.
./exampleB1: symbol lookup error: ./exampleB1: undefined symbol: G4cout

I was previously able to get the example to run, at some point without modifications, the example is no longer able to run. I have never run into this problem before, and some advice would be much appreciated. Thank you very much for your time and help.

Just to double check, is the compilation with the unmodified or modified exampleB1 code? If the latter, what modifications have you made?

One thing to do to try and trace what’s happening would be to run the program as:

$ LD_DEBUG=symbols ./exampleB1

That should print out quite a bit of info about what’s symbols are being looked up from where. If you could post any relevant error messages here, we can look through (they’ll obviously be towards the end). If you’re not sure, post the entire output in a file attachment.

Hello bmorgan,
I have not made any modifications to the source Code, and I have tried changing around the cmake PREFIX value to no avail. here are all the G4cout outputs I got after running the command you recommended
Thank you for your assistance, this has been bugging this whole week.

44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4Tree.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4FR.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4GMocren.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4visHepRep.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4RayTracer.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4VRML.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4vis_management.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4modeling.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4interfaces.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4physicslists.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4run.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4event.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4tracking.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4analysis.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4particles.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4geometry.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4materials.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4intercoms.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4global.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4clhep.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libstdc++.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libgcc_s.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libc.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4graphics_reps.so [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libm.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libpthread.so.0 [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4digits_hits.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4zlib.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libX11.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4processes.so [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libQtGui.so.4 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libQtCore.so.4 [0]
     44738: symbol=G4cout;  lookup in file=/usr/local/geant4/geant4.10.04p2/lib/libG4track.so [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libexpat.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/lib64/ld-linux-x86-64.so.2 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libxcb.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libdl.so.2 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libfontconfig.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libaudio.so.2 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libglib-2.0.so.0 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libpng16.so.16 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libz.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libfreetype.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libgobject-2.0.so.0 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libSM.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libICE.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libXi.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libXrender.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libXext.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/librt.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libXau.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libXdmcp.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libXt.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libpcre.so.3 [0]
     44738: symbol=G4cout;  lookup in file=/usr/lib/x86_64-linux-gnu/libffi.so.6 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libuuid.so.1 [0]
     44738: symbol=G4cout;  lookup in file=/lib/x86_64-linux-gnu/libbsd.so.0 [0]
     44738: ./exampleB1: error: symbol lookup error: undefined symbol: G4cout (fatal)
./exampleB1: symbol lookup error: ./exampleB1: undefined symbol: G4cout

Thanks for the info - I’m still a little stumped on this. Was this install of Geant4 built with multithreading support, and how long ago was it built/installed? Could you try:

$ nm /usr/local/geant4/geant4.10.04p2/lib/libG4global.so | grep G4cout

and post the output here please?

yea this is definitely a head scratcher. I’m pretty sure it was built with multithreading. I use a public Geant4 install on a server with people who do much larger simulations so I imagine they need it. I cant answer when it was built/installed though.

here is the output for the command.

0000000000000078 B G4coutbuf_p
0000000000000088 B G4cout_p
0000000000016bb0 t _GLOBAL__sub_I_G4coutDestination.cc
0000000000016d80 t _GLOBAL__sub_I_G4coutFormatters.cc
000000000025dfe0 b _ZGVZN16G4coutFormatters18SetupStyleGloballyERK8G4StringE2ss
000000000004b900 T _ZN16G4coutFormatters11HandleStyleEP17G4coutDestinationRK8G4String
000000000025e0c0 b _ZN16G4coutFormatters12_GLOBAL__N_111masterStyleE
000000000025e0a0 b _ZN16G4coutFormatters12_GLOBAL__N_111SysLogStyleE
000000000025e080 b _ZN16G4coutFormatters12_GLOBAL__N_112DefaultStyleE
000000000025e040 b _ZN16G4coutFormatters12_GLOBAL__N_112transformersE
000000000004bdc0 t _ZN16G4coutFormatters12_GLOBAL__N_19transformER8G4StringRKS1_
000000000004b830 T _ZN16G4coutFormatters14GetMasterStyleEv
000000000004b800 T _ZN16G4coutFormatters14SetMasterStyleERK8G4String
000000000004cd90 T _ZN16G4coutFormatters16RegisterNewStyleERK8G4StringRSt8functionIFiP17G4coutDestinationEE
000000000004ba00 T _ZN16G4coutFormatters18SetupStyleGloballyERK8G4String
000000000025e100 b _ZN16G4coutFormatters2IDL6SYSLOGE
000000000025e0e0 b _ZN16G4coutFormatters2IDL7DEFAULTE
000000000004cae0 T _ZN16G4coutFormatters5NamesEv
00000000000460d0 T _ZN17G4coutDestination13ReceiveG4cerrERK8G4String
00000000000460d0 t _ZN17G4coutDestination13ReceiveG4cerrERK8G4String.localalias.26
0000000000046100 T _ZN17G4coutDestination13ReceiveG4coutERK8G4String
0000000000046100 t _ZN17G4coutDestination13ReceiveG4coutERK8G4String.localalias.27
0000000000046460 T _ZN17G4coutDestination14ReceiveG4cerr_ERK8G4String
0000000000046230 T _ZN17G4coutDestination14ReceiveG4cout_ERK8G4String
0000000000046020 T _ZN17G4coutDestination17ResetTransformersEv
000000000025df48 B _ZN17G4coutDestination23masterG4coutDestinationE
0000000000046210 T _ZN17G4coutDestinationD0Ev
0000000000046130 T _ZN17G4coutDestinationD1Ev
0000000000046130 T _ZN17G4coutDestinationD2Ev
000000000004e680 T _ZN21G4FilecoutDestination13ReceiveG4coutERK8G4String
000000000004e1e0 T _ZN21G4LockcoutDestination13ReceiveG4coutERK8G4String
000000000004af40 W _ZN22G4MulticoutDestination13ReceiveG4coutERK8G4String
000000000004ea60 T _ZN23G4BuffercoutDestination11FlushG4coutEv
000000000004e770 T _ZN23G4BuffercoutDestination13ReceiveG4coutERK8G4String
000000000004e2e0 T _ZN30G4MasterForwardcoutDestination13ReceiveG4coutERK8G4String
000000000004e090 W _ZNSt10_HashtableINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_St8functionIFiP17G4coutDestinationEEESaISD_ENSt8__detail10_Select1stESt8equal_toIS5_ESt4hashIS5_ENSF_18_Mod_range_hashingENSF_20_Default_ranged_hashENSF_20_Prime_rehash_policyENSF_17_Hashtable_traitsILb1ELb0ELb1EEEE21_M_insert_unique_nodeEmmPNSF_10_Hash_nodeISD_Lb1EEE
000000000004df60 W _ZNSt10_HashtableINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_St8functionIFiP17G4coutDestinationEEESaISD_ENSt8__detail10_Select1stESt8equal_toIS5_ESt4hashIS5_ENSF_18_Mod_range_hashingENSF_20_Default_ranged_hashENSF_20_Prime_rehash_policyENSF_17_Hashtable_traitsILb1ELb0ELb1EEEE9_M_rehashEmRKm
000000000004d9d0 W _ZNSt10_HashtableINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_St8functionIFiP17G4coutDestinationEEESaISD_ENSt8__detail10_Select1stESt8equal_toIS5_ESt4hashIS5_ENSF_18_Mod_range_hashingENSF_20_Default_ranged_hashENSF_20_Prime_rehash_policyENSF_17_Hashtable_traitsILb1ELb0ELb1EEEED1Ev
000000000004d9d0 W _ZNSt10_HashtableINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt4pairIKS5_St8functionIFiP17G4coutDestinationEEESaISD_ENSt8__detail10_Select1stESt8equal_toIS5_ESt4hashIS5_ENSF_18_Mod_range_hashingENSF_20_Default_ranged_hashENSF_20_Prime_rehash_policyENSF_17_Hashtable_traitsILb1ELb0ELb1EEEED2Ev
000000000004d3d0 W _ZNSt13unordered_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFiP17G4coutDestinationEESt4hashIS5_ESt8equal_toIS5_ESaISt4pairIKS5_SA_EEED1Ev
000000000004d3d0 W _ZNSt13unordered_mapINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFiP17G4coutDestinationEESt4hashIS5_ESt8equal_toIS5_ESaISt4pairIKS5_SA_EEED2Ev
000000000004b7e0 t _ZNSt14_Function_base13_Base_managerIN16G4coutFormatters12_GLOBAL__N_1UlP17G4coutDestinationE0_EE10_M_managerERSt9_Any_dataRKS7_St18_Manager_operation
000000000004b790 t _ZNSt14_Function_base13_Base_managerIN16G4coutFormatters12_GLOBAL__N_1UlP17G4coutDestinationE_EE10_M_managerERSt9_Any_dataRKS7_St18_Manager_operation
000000000004b7b0 t _ZNSt17_Function_handlerIFiP17G4coutDestinationEN16G4coutFormatters12_GLOBAL__N_1UlS1_E0_EE9_M_invokeERKSt9_Any_dataOS1_
000000000004bb10 t _ZNSt17_Function_handlerIFiP17G4coutDestinationEN16G4coutFormatters12_GLOBAL__N_1UlS1_E_EE9_M_invokeERKSt9_Any_dataOS1_
000000000004d600 W _ZNSt4pairIKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFiP17G4coutDestinationEEEC1IRK8G4StringRSB_Lb1EEEOT_OT0_
000000000004d5c0 W _ZNSt4pairIKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFiP17G4coutDestinationEEED1Ev
000000000004d5c0 W _ZNSt4pairIKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEESt8functionIFiP17G4coutDestinationEEED2Ev
000000000004b3a0 W _ZNSt6vectorISt10unique_ptrI17G4coutDestinationSt14default_deleteIS1_EESaIS4_EE17_M_realloc_insertIJS4_EEEvN9__gnu_cxx17__normal_iteratorIPS4_S6_EEDpOT_
000000000004d330 W _ZNSt8functionIFiP17G4coutDestinationEED1Ev
000000000004d330 W _ZNSt8functionIFiP17G4coutDestinationEED2Ev
                 w _ZTH11G4coutbuf_p
                 w _ZTH8G4cout_p
000000000025c5d0 V _ZTI17G4coutDestination
000000000025c8d8 d _ZTIN16G4coutFormatters12_GLOBAL__N_1UlP17G4coutDestinationE0_E
000000000025c8c8 d _ZTIN16G4coutFormatters12_GLOBAL__N_1UlP17G4coutDestinationE_E
000000000025c6b0 V _ZTISt12_Vector_baseISt10unique_ptrI17G4coutDestinationSt14default_deleteIS1_EESaIS4_EE
000000000025c6c0 V _ZTISt6vectorISt10unique_ptrI17G4coutDestinationSt14default_deleteIS1_EESaIS4_EE
0000000000051e30 V _ZTS17G4coutDestination
00000000000524a0 r _ZTSN16G4coutFormatters12_GLOBAL__N_1UlP17G4coutDestinationE0_E
0000000000052460 r _ZTSN16G4coutFormatters12_GLOBAL__N_1UlP17G4coutDestinationE_E
0000000000051f00 V _ZTSSt12_Vector_baseISt10unique_ptrI17G4coutDestinationSt14default_deleteIS1_EESaIS4_EE
0000000000051f60 V _ZTSSt6vectorISt10unique_ptrI17G4coutDestinationSt14default_deleteIS1_EESaIS4_EE
000000000025c5e0 V _ZTV17G4coutDestination
000000000025e000 b _ZZN16G4coutFormatters18SetupStyleGloballyERK8G4StringE2ss

Okay I tried to change all the G4cout to std::cout and there was a new error that came up.

<<< Reference Physics List QBBC 
-------- EEEE ------- G4Exception-START -------- EEEE -------*** G4Exception : Run3001 issued by : G4RunManager::SetUserThreadInitialization()Base-class G4RunManager cannot take G4UserWorkerThreadInitialization. Use G4MTRunManager.*** Fatal Exception *** core dump *** **** Track information is not available at this moment **** Step information is not available at this moment
-------- EEEE -------- G4Exception-END --------- EEEE -------

*** G4Exception: Aborting execution ***

Thanks again for the info, and also the extra test. I think the install of Geant4 is definitely MT, but for some reason your application is compiling without it. If you’re using CMake to build the application, could you run (in the build directory)

$ make clean
$ make VERBOSE=1

and post the output here please? In the output, the compile commands should have a -DG4MULTITHREADED flags present.

Good morning, I ran the commands with Verbose=1 and there was this large output I ran a search program and It could find DG4MULTITHREADED flag anywhere. Do you think there was something that I may have messed up with cmake?
Error.txt (93.0 KB)

I dont know If you will get notified for the other post, so this is to ensure you get a pop-up. Thank you again for your help.

O.k., in the output in that file, the build of your application is picking up your own build of Geant4 10.7.1, e.g.:

 [12%] Building CXX object CMakeFiles/exampleB1.dir/exampleB1.cc.o
/usr/bin/c++  -DG4LIB_BUILD_DLL -DG4UI_USE_TCSH -isystem /home/jfehrenbach/geant4-10.7.1/source/analysis/g4tools/include ....

and also linking it to those libraries and setting the RPATH accordingly. However, when you’re running the example, it’s trying to use the Geant4 10.4 libraries under /usr/local/geant4/geant4.10.04p2/lib, so that’s the immediate cause of the issue. There’s two possible causes for this:

  1. Is LD_LIBRARY_PATH set in your environment and does it include /usr/local/geant4/geant4.10.04p2/lib?
  2. Are you doing a make install before running the application? CMake will strip the RPATH and consequently might be picking up the “bad” libs either from LD_LIBRARY_PATH or any settings in /etc/ld.so.conf that point the linker to /usr/local/geant4/geant4.10.04p2/lib

I checked the LD_LIBRARY_PATH and it included the path you mentioned. I tried running make install but it followed an error. I’m pretty sure it has to do with the CMAKE_INSTALL_PREFIX. I have it set to /home/jfehrenbach/B1.
However, I do not know what I should change it to if that is the issue.
I used ccmake in advanced mode and found at the bottom there are two which also may be the cause for the issue.

Geant4_DIR=/home/jfehrenbach/ geant4-10.7.1-build
PTL_DIR=/home/jfehrenbach/geant4-10.7.1-build/source/externals/ptl

These directories are pathways to a local Geant4 version I do not want to use. However, I tried using the /usr/local/geant4/geant4.10.04p2 and couldn’t find a directory inside called source. Do you know where these are supposed to be going? Thank you again.

I don’t think you need to install here (and the prefix shouldn’t be an issue) as the executable will be runnable directly from where it is built. To use the Geant4 install under /usr/local, I’d try the following steps:

  • Check that there is a file /usr/local/geant4/geant4.10.04p2/lib/Geant4-10.4.2/Geant4Config.cmake (or at least one named Geant4Config.cmake somewhere under /usr/local/geant4/geant4.10.04p2

  • Delete the contents of the directory where you’re building the application - going from the output of your previous build, this would be

    $ cd /home/jfehrenbach/B1build
    
  • In that directory, re-run CMake as:

    $ cmake -DCMAKE_PREFIX_PATH=/usr/local/geant4/geant4.10.04p2 /home/jfehrenbach/B1
    

    It can also be run equivalently, assuming the presence of /usr/local/geant4/geant4.10.04p2/lib/Geant4-10.4.2/Geant4Config.cmake, as

    $ cmake -DGeant4_DIR=/usr/local/geant4/geant4.10.04p2/lib/Geant4-10.4.2 /home/jfehrenbach/B1
    
  • Now try rebuilding and running:

    $ make VERBOSE=1
    # check the compile commands have `-isystem` entries for /usr/local/geant4/geant4.10.04.p2/include/Geant4` etc
    $ ./exampleB1
    

NB: double check that the sources you have for the example have been copied from the 10.4.2 release as those from 10.7.1 are likely not to work when compiled against 10.4.2.

1 Like

Thank you so much! that fixed it up! I cannot thank you enough.

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