# Compilation Error in Geant4 B1 Example

**URL:** <https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214>\
**Category:** Getting Started\
**Created:** [May 5, 2024, 3:11pm UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214 "2024-05-05T15:11:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ayoub-Aamar](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ayoub-aamar/32/8171_2.png) [@Ayoub-Aamar](https://geant4-forum.web.cern.ch/u/Ayoub-Aamar)\
**Post date:** [May 5, 2024, 3:11pm UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/1 "2024-05-05T15:11:00Z")

</div>

Geant4 Version: 11.2.1  
Operating System: Ubuntu 22.04.4 LTS  
Conda Version: 23.9.0  
CMake Version: 3.26.3

Hello,

I’m encountering a compilation error while trying to build the Geant4 B1 example. Here’s the error message I’m receiving:

```auto
(G4-Ayoub) mlahdour@ThinkCentre:~/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B1/build$ make
[12%] Building CXX object CMakeFiles/exampleB1.dir/exampleB1.cc.o
/home/mlahdour/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B1/exampleB1.cc: In function ‘int main(int, char**)’:
/home/mlahdour/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B1/exampleB1.cc:80:50: error: no matching function for call to ‘G4VisExecutive::G4VisExecutive(int&, char**&)’
   80 | auto visManager = new G4VisExecutive(argc, argv);
      | ^
In file included from /usr/local/include/Geant4/G4VisExecutive.hh:132,
                 from /home/mlahdour/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B1/exampleB1.cc:38:
/usr/local/include/Geant4/G4VisExecutive.icc:126:1: note: candidate: ‘G4VisExecutive::G4VisExecutive(const G4String&)’
  126 | G4VisExecutive::G4VisExecutive (const G4String& verbosityString):
      | ^ ~~~~~
/usr/local/include/Geant4/G4VisExecutive.icc:126:1: note: candidate expects 1 argument, 2 provided
/home/mlahdour/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B1/exampleB1.cc:111:10: error: type ‘<type error>’ argument given to ‘delete’, expected pointer
  111 | delete visManager;
      | ^~~~
make[2]: * [CMakeFiles/exampleB1.dir/build.make:76 : CMakeFiles/exampleB1.dir/exampleB1.cc.o] Erreur 1
make[1]: * [CMakeFiles/Makefile2:84 : CMakeFiles/exampleB1.dir/all] Erreur 2
make: * [Makefile:136 : all] Erreur 2

```

- I’ve created a new Conda environment specifically for this version to avoid conflicts with the older version 11.1.2.

Thank you,

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [May 5, 2024, 3:51pm UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/2 "2024-05-05T15:51:55Z")

</div>

Hi

First, when supplying code or output, please use triple-back-accent (``` on a separate line), then the code/output, terminated by another ```. Or an attachment. _Not_ an screenshot.

Mmm. Seems you are using an old version of `G4VisExecutive.icc`. Do you have your own copy? Should not be needed. In your main program file:

```auto
#include "G4VisExecutive.hh"

```

should be enough. It includes `G4VisExecutive.icc` from the geant4 source tree.

At least, that’s how it looks. Let us know if this is a misdiagnosis.

John

---

<div class="post-metadata">

**Author:** ![Ayoub-Aamar](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ayoub-aamar/32/8171_2.png) [@Ayoub-Aamar](https://geant4-forum.web.cern.ch/u/Ayoub-Aamar)\
**Post date:** [May 5, 2024, 4:14pm UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/3 "2024-05-05T16:14:58Z")

</div>

Thank you for your remark, John. Yes, indeed, `"G4VisExecutive.hh"` is included in the main file.

```auto
/// \file exampleB2b.cc
/// \brief Main program of the B2b example

#include "DetectorConstruction.hh"
#include "ActionInitialization.hh"

#include "G4RunManagerFactory.hh"
#include "G4SteppingVerbose.hh"
#include "G4UImanager.hh"
#include "FTFP_BERT.hh"
#include "G4StepLimiterPhysics.hh"

#include "Randomize.hh"

#include "G4VisExecutive.hh"
#include "G4UIExecutive.hh"

//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......

int main(int argc,char** argv)
{ 

```

Additionally, I’ve tested with another extended example (Hadr04). Here’s the output:

```auto
(G4-Ayoub) mlahdour@ThinkCentre:~/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/extended/hadronic/Hadr04/build$ ./Hadr04 
Available UI session types: [tcsh, csh]

**********************
 Geant4 version Name: geant4-11-01-patch-02 [MT] (15-June-2023)
  << in Multi-threaded mode >> 
                       Copyright : Geant4 Collaboration
                      References : NIM A 506 (2003), 250-303
                                 : IEEE-TNS 53 (2006), 270-278
                                 : NIM A 835 (2016), 186-225
                             WWW : http://geant4.org/
**********************

Visualization Manager instantiating with verbosity "warnings (3)"...
Visualization Manager initialising...
Registering graphics systems...

You have successfully registered the following graphics systems.
Registered graphics systems are:
  ASCIITree (ATree)
  DAWNFILE (DAWNFILE)
  G4HepRepFile (HepRepFile)
  RayTracer (RayTracer)
  VRML2FILE (VRML2FILE)
  gMocrenFile (gMocrenFile)
  TOOLSSG_OFFSCREEN (TSG_OFFSCREEN)
  TOOLSSG_OFFSCREEN (TSG_OFFSCREEN, TSG_FILE)

Registering model factories...

You have successfully registered the following model factories.
Registered model factories:
  generic
  drawByAttribute
  drawByCharge
  drawByOriginVolume
  drawByParticleID
  drawByEncounteredVolume

Registered models:
  None

Registered filter factories:
  attributeFilter
  chargeFilter
  originVolumeFilter
  particleFilter
  encounteredVolumeFilter

Registered filters:
  None

You have successfully registered the following user vis actions.
Run Duration User Vis Actions: none
End of Event User Vis Actions: none
End of Run User Vis Actions: none

Some /vis commands (optionally) take a string to specify colour.
"/vis/list" to see available colours.
PreInit>   

```

---

<div class="post-metadata">

**Author:** ![Ayoub-Aamar](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ayoub-aamar/32/8171_2.png) [@Ayoub-Aamar](https://geant4-forum.web.cern.ch/u/Ayoub-Aamar)\
**Post date:** [May 5, 2024, 4:23pm UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/4 "2024-05-05T16:23:03Z")

</div>

when I run cmake …, it indicates that Geant4 version 11.1.2 is found, even though I’m working with version 11.2.1.

```auto
(base) mlahdour@ThinkCentre:~/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B3/B3a/build$ cmake ..
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found EXPAT: /usr/lib/x86_64-linux-gnu/libexpat.so (found suitable version "2.4.7", minimum required is "2.4.7") 
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Found Geant4: /usr/local/lib/cmake/Geant4/Geant4Config.cmake (found version "11.1.2") 
-- Configuring done (0.3s)
-- Generating done (0.0s)
-- Build files have been written to: /home/mlahdour/Bureau/Ayoub/software/geant4-v11.2.1-install/share/Geant4/examples/basic/B3/B3a/build

```

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [May 6, 2024, 4:52pm UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/5 "2024-05-06T16:52:32Z")

</div>

Hi Ayoub

That certainly explains it. Of course, one must compile and link with the correct Geant4 code and libraries. Do you know how to do this? Can you correct the above problem yourself? (Have a look at the Installation Guide.) Let us know if it fixes things for you.

John

---

<div class="post-metadata">

**Author:** ![Ayoub-Aamar](https://geant4-forum.web.cern.ch/user_avatar/geant4-forum.web.cern.ch/ayoub-aamar/32/8171_2.png) [@Ayoub-Aamar](https://geant4-forum.web.cern.ch/u/Ayoub-Aamar)\
**Post date:** [May 10, 2024, 11:19am UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/6 "2024-05-10T11:19:06Z")

</div>

Hi John,

Thanks for your reply and clarification! You’re absolutely right, I needed to link the libraries.

I was able to fix it by running `. geant4make.sh` within the following path :

```auto
/path/to/geant4-v11.0.0-install/geant4.sh

```

Ayoub

---

<div class="post-metadata">

**Author:** ![allison](https://geant4-forum.web.cern.ch/letter_avatar_proxy/v4/letter/a/90db22/32.png) [@allison](https://geant4-forum.web.cern.ch/u/allison)\
**Post date:** [May 10, 2024, 11:42am UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/7 "2024-05-10T11:42:11Z")

</div>

Hi Ayoub

That’s great. Thanks for letting us know.

John

---

<div class="post-metadata">

**Author:** ![system](https://geant4-forum.web.cern.ch/uploads/default/original/1X/ce519a43ebdf7ac48a98a03c6ad6eea013b68c46.png) [@system](https://geant4-forum.web.cern.ch/u/system)\
**Post date:** [June 9, 2024, 11:42am UTC](https://geant4-forum.web.cern.ch/t/compilation-error-in-geant4-b1-example/12214/8 "2024-06-09T11:42:12Z")

</div>

Closed on June 9, 2024, 11:42am UTC

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