Compiling TestEM0 or B1 in Anaconda Env

I have:
conda version 4.10.3
Python version 3.8.12

Trying to compile any Geant4 examples on Linux Mint 19.2 I get:

– The C compiler identification is GNU 9.3.0
– The CXX compiler identification is GNU 9.3.0
– Check for working C compiler: /home/peter/anaconda3/bin/x86_64-conda-linux-gnu-cc
– Check for working C compiler: /home/peter/anaconda3/bin/x86_64-conda-linux-gnu-cc - works
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Detecting C compile features
– Detecting C compile features - done
– Check for working CXX compiler: /home/peter/anaconda3/bin/x86_64-conda-linux-gnu-c++
– Check for working CXX compiler: /home/peter/anaconda3/bin/x86_64-conda-linux-gnu-c++ - works
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Detecting CXX compile features
– Detecting CXX compile features - done
– Found EXPAT: /home/peter/anaconda3/lib/libexpat.so (found suitable version “2.4.1”, minimum required is “2.4.1”)
– Found ZLIB: /home/peter/anaconda3/lib/libz.so (found suitable version “1.2.11”, minimum required is “1.2.11”)
– Looking for pthread.h
– Looking for pthread.h - found
– Performing Test CMAKE_HAVE_LIBC_PTHREAD
– Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
– Check if compiler accepts -pthread
– Check if compiler accepts -pthread - yes
– Found Threads: TRUE
– Found XercesC: /home/peter/anaconda3/lib/libxerces-c.so (found suitable version “3.2.3”, minimum required is “3.2.3”)
– Found Freetype: /home/peter/anaconda3/lib/libfreetype.so (found suitable version “2.10.4”, minimum required is “2.10.4”)
– Found X11: /home/peter/anaconda3/include
– Looking for XOpenDisplay in /home/peter/anaconda3/lib/libX11.so;/home/peter/anaconda3/lib/libXext.so
– Looking for XOpenDisplay in /home/peter/anaconda3/lib/libX11.so;/home/peter/anaconda3/lib/libXext.so - found
– Looking for gethostbyname
– Looking for gethostbyname - found
– Looking for connect
– Looking for connect - found
– Looking for remove
– Looking for remove - found
– Looking for shmat
– Looking for shmat - found
– Looking for IceConnectionNumber in ICE
– Looking for IceConnectionNumber in ICE - found
– Found OpenGL: /home/peter/anaconda3/x86_64-conda-linux-gnu/sysroot/usr/lib/libGL.so
– Configuring done
– Generating done
– Build files have been written to: /home/peter/anaconda3/share/Geant4-10.7.2/examples/basic/B1
(base) peter@Beta:~/anaconda3/share/Geant4-10.7.2/examples/basic/B1$ make
Scanning dependencies of target exampleB1
[ 12%] Building CXX object CMakeFiles/exampleB1.dir/exampleB1.cc.o
In file included from /home/peter/anaconda3/x86_64-conda-linux-gnu/include/c++/9.3.0/bits/locale_facets_nonio.h:39,
from /home/peter/anaconda3/x86_64-conda-linux-gnu/include/c++/9.3.0/locale:41,
from /home/peter/anaconda3/x86_64-conda-linux-gnu/include/c++/9.3.0/iomanip:43,
from /home/peter/anaconda3/include/Geant4/G4EnvironmentUtils.hh:45,
from /home/peter/anaconda3/include/Geant4/globals.hh:59,
from /home/peter/anaconda3/include/Geant4/G4VUserDetectorConstruction.hh:37,
from /home/peter/anaconda3/share/Geant4-10.7.2/examples/basic/B1/include/B1DetectorConstruction.hh:33,
from /home/peter/anaconda3/share/Geant4-10.7.2/examples/basic/B1/exampleB1.cc:30:
/home/peter/anaconda3/x86_64-conda-linux-gnu/include/c++/9.3.0/ctime:80:11: error: ‘::timespec_get’ has not been declared
** 80 | using ::timespec_get;**
| ^~~~~~~~~~~~
CMakeFiles/exampleB1.dir/build.make:82: recipe for target ‘CMakeFiles/exampleB1.dir/exampleB1.cc.o’ failed
make[2]: *** [CMakeFiles/exampleB1.dir/exampleB1.cc.o] Error 1
CMakeFiles/Makefile2:96: recipe for target ‘CMakeFiles/exampleB1.dir/all’ failed
make[1]: *** [CMakeFiles/exampleB1.dir/all] Error 2
Makefile:149: recipe for target ‘all’ failed
make: *** [all] Error 2

You can trace error: ‘::timespec_get’ has not been declared
** 80 | using ::timespec_get;**

to ctime in /anaconda3/x86_64-conda-linux-gnu/include/c++/9.3.0

and the lines:

#if __cplusplus >= 201703L && defined(_GLIBCXX_HAVE_TIMESPEC_GET)
#undef timespec_get
namespace std
{
using ::timespec;
using ::timespec_get;
} // namespace std
#endif

where timespec_get is undefined?

Can anybody help?

I suspect this is the same issue (channel toolchain mismatch) as reported here with ROOT: "error: '::timespec_get' has not been declared" with conda root package - #6 by kkrizka - ROOT - ROOT Forum

Try the fixes/resolution reported in this post "error: '::timespec_get' has not been declared" with conda root package - #8 by kkrizka - ROOT - ROOT Forum to see if that resolves things. You’ll also need to delete the current build directory of exampleB1 to avoid CMake caching issues when you next try building it.

I got the TestEm0 to compile and link and execute (C++). However this program in the sourc-forge geant4 install does not satisfy the spirit of running geant4 via python. In the testem0 python example it reads:
#!/usr/bin/python

==================================================================

python script for TestEm0 python version

==================================================================

import Geant4 as g4
import TestEm0

==================================================================

user actions in python

==================================================================

==================================================================

main

==================================================================

myDC= TestEm0.DetectorConstruction()
g4.gRunManager.SetUserInitialization(myDC)

myPL= TestEm0.PhysicsList()
g4.gRunManager.SetUserInitialization(myPL)

set user actions…

myPGA= TestEm0.PrimaryGeneratorAction(myDC)
g4.gRunManager.SetUserAction(myPGA)

myRA= TestEm0.RunAction(myDC,myPGA)

set user action classes

g4.gRunManager.SetUserAction(myRA)

Note it has import TestEm0 which is a module class/package that should satisfy myDC= TestEm0.DetectorConstruction(). I found such a TestEm0 (not the one given in source-forge install). But to make this work I would have to build a c++ library from a bunch of files then wrap them so they were importable from python. Clearly someone has done this since it appears in the program above. I have a simple question, “where can I get working examples of geant4 python programs with working modules?” They must exist since these programs are published. Can you tell me where to find them?

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