Hi everyone, I hope you are well. I have been getting an error trying to compile my user code. I am using Geant4, for electronic brachytherapy application to generate voxelized dose distribution to calculate TG-43 parameters (Brachytherapy analytical formulations for dose distribution). Everything compiles just fine except for when my main is trying to be linked, I get undefined reference errors as such:
/home/shirin/geant4_workdir/tmp/Linux-g++/TG43/exe/TG43.o: In function
main': TG43.cc:(.text.startup+0x1e8): undefined reference to G4cout_p’
/home/shirin/geant4_workdir/tmp/Linux-g++/TG43/exe/TG43.o:(.data.rel.ro._ZTV14G4VisExecutive[_ZTV14G4VisExecutive]+0x110): undefined reference to `G4VisManager::SetUpForAThread()’
collect2: error: ld returned 1 exit status
/home/shirin/TPS/Geant4/geant4.10.02.p02/config/binmake.gmk:410: recipe for target ‘/home/shirin/geant4_workdir/bin/Linux-g++/TG43’ failed
make: *** [/home/shirin/geant4_workdir/bin/Linux-g++/TG43] Error 1
I have been trying to check the references and the libraries and it seems to be fine. Your help will be greatly appreciated.
It’s possible that there’s some mixup in the build/use settings between the installed libraries and the application. The missing symbols would seem to indicate the application is being built in multithreaded mode, but the libraries in
/home/shirin/TPS/Geant4/geant4.10.02.p02 were not (or vice versa). Though 10.2 is very old now, I think that can be checked in the GNUMake system via the
G4MULTITHREADED environment variable - if the install sets that, then the libraries should be MT.
Thank you for your help. However, I have previously compiled other multithreaded Geant4 codes and I have this problem only with this one. Any ideas where I could have gone wrong?
Are you using CMake to configure your build system? Or are you using a pre-existing makefile to compile your code? If you’re using a makefile directly you may have to check that the path to the Geant4 install is correctly configured in the makefile.
If the above advice doesn’t work, we could use some more information regarding what operating system you are compiling on, what commands you are invoking to compile, and what your CMakeLists file looks like.
Thank you for your response. Yes, I am making with cmake and I can share my GNUmake file here. It ultimately just doesn’t work for this code. I am not sure why.
name := TG43
G4TARGET := $(name)
G4EXLIB := true
G4INSTALL = /Users/Shirin/geant4.10.02.p02-install
EXTRALIBS += $(shell $(ROOTSYS)/bin/root-config --glibs)
CPPFLAGS += $(shell $(ROOTSYS)/bin/root-config --cflags)
all: lib bin
When you call CMake it doesn’t work for this code? I think that is occuring because there is no CMakeLists file in your directory, which is okay because you already have a pre-written makefile.
On the computer you are running the code, is Geant4 installed at “/Users/Shirin/geant4.10.02.p02-install”, or is it installed elsewhere? If it’s installed elsewhere you can update the path in your makefile to the location of your install.
Yes I just make with make. I don’t use the cmakelist. It is installed elsewhere, but I changed it to that path, and tried, and still the same error. I also tried another similar code with the exact same GNUmake file and it was compiled just fine, so I am really unsure of where the problem is stemming from. I really appreciate your help though thank you so much Joseph
In your MakeFile could you add two lines between “all: lib bin” and the include statement? This will just let us know if you compiled with multithreading enabled and if the location of your Geant4 install directory has been found succesfully. If you add them, can you let us know what the output is when you invoke make again?
all: lib bin
$(info Geant4 multithreaded state is $(G4MULTITHREADED))
$(info Geant4 install location is $(G4INSTALL))
I’m able to compile the same TG43 Geant4 user code you are trying to on Geant4 11.1 with multithreading enabled. So I’m hopeful that we can figure out why it isn’t working.
Thank you so much for your suggestions. For some reason it still doesn’t work. I am going to open a different workspace to see if this is a path problem from the visual studio code. My version is slightly different from yours in that I implemented the electronic brachytherapy into it, but I have to make sure it works properly and it does compile and run. I am out of ideas, but I’ll try to see how it goes.
I actually compiled the original version from GitLab on my local computer again, and unfortunately I get the same linker error. I am not sure what the issue is at this point. I also tried compiling another package that was previously multithreaded. That does compile. I think there is a problem or version mismatch here in the code itself. I will update you if I find anything, and if you have an idea please let me know.