Error running example with Visual studio 2019 and GEANT4_10_06

I used VS2019 and cmake 3.16.4 to install the Geant4 on my Win10, and supposedly, it is installed correctly, since I have not seen any errors during the process.

I was able to build exampleB1.exe by VS2019, however when I try to run the built *.exe (under Debug folder) as administrator, I get the attached error (fig. run as administrator.jpg).
When I use “exampleB1.exe …\run1.mac” in cmd to run the example, I get the attached error (fig. cmd.jpg).

What am I missing?
Any help is greatly appreciated.

Just to confirm, this is the stock exampleB1 with no modification to the code? The only other things to check are:

  • If built “as-is” with CMake on Windows, there should be a separate Debug folder under B1-build where the exampleB1.exe is. I know you mentioned this folder, but the command prompt in the screenshot doesn’t appear to show this. Also, unless this folder has been added to the PATH, the exec needs to be run using an absolute/relative path, e.g. .\Debug\exampleB1.exe run1.mac
  • Which build mode did you use to build/install Geant4? If you built it in Release mode, then the example should be as well.

Hi. This example compiles and runs OK for me. I’m using Visual Studio 2019 and Geant4.10.06.p01 with cmake 3.16.2.

I did the following:

Created a folder for the build and moved into it:

mkdir b1-build
cd b1-build

Ran cmake to create the various makefiles that are required:

cmake -DGeant4_DIR=d:\path\to\geant4_10_06_p01-MT-install\lib\Geant4-10.6.1 d:\path\to\geant4_10_06_p01-MT-install\share\Geant4-10.6.1\examples\basic\b1

Ran the cmake --build command to compile the code:

cmake --build . --config Release

Then ran the executable (without moving into the .\Release folder):

.\Release\exampleB1.exe run1.mac

Entering .\Release\exampleB1.exe on its own runs the GUI for me (I compiled Geant4 with QT)

Have you configured the required environment variables so that your simulation knows where to find the Geant4 data files etc?

Kind regards


Thank you! After 3 hours of hell this solved the my problem.