Errors when trying to build Geant4

Hello everyone,

I am new to Geant4 (and to C++) so please bear with me as I try to get the software up and running.

I have been following the steps listed in [1]:

  • I downloaded and installed Visual Studio 2019.

  • I downloaded CMake 3.15.4 and executed its installer.

  • I have downloaded Geant4 4.10.05 and extracted its contents in E:/Geant4

  • I opened the CMake GUI. After “Where is the source code” I typed “E:/Geant4/Geant4_10_05_p01”. After “Where to build the binaries” I typed “E/Geant4/Geant4_10_05-build”. (Note, these folders already exist).

  • I clicked ‘Configure’ , chose ‘Visual Studio 16 2019’ as my specified generator and made sure the ‘Use default native compilers’ radial button was selected. I clicked ‘Finish’.

  • I got a few error messages, see below. I select the boxes for ‘GEANT4_INSTALL_DATA’ and ‘GEANT4_USE_OPENGL_WIN32’.

  • I clicked ‘Configure’ and all configuration issues were resolved (no red lines).

  • I then clicked ‘Generate’. It generates the Visual Studio project file.

  • I close CMake. I open Visual Studio 2019 and I open the Geant4.sln project file that was generated.

  • I right click on ‘INSTALL’ under Solution Explorer and click ‘Build’.

  • After more than an hour, I get Build: 37 succeeded, 10 failed, 0 up-to-date, 0 skipped"

Below, I write all the error/fail messages that I found when searching through the text that printed out in the command window as the project was building.

"37>G4VisCommandsViewer.cc
37>The contents of are only available with C++17 or later.
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1221,62): error C2079: ‘filePattern’ uses undefined class ‘std::experimental::filesystem::v1::path’
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1221,63): error C2440: ‘initializing’: cannot convert from ‘G4String’ to ‘int’
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1221,54): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1260,55): error C2039: ‘directory_iterator’: is not a member of ‘std::experimental::filesystem::v1’
37>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\fstream(40): message : see declaration of ‘std::experimental::filesystem::v1’
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1260,85): error C3861: ‘directory_iterator’: identifier not found
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1261,51): error C2039: ‘directory_iterator’: is not a member of ‘std::experimental::filesystem::v1’
37>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.23.28105\include\fstream(40): message : see declaration of ‘std::experimental::filesystem::v1’
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1261,69): error C3861: ‘directory_iterator’: identifier not found
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1264,22): error C2530: ‘file’: references must be initialized
37>G4VisCommandsViewerDefault.cc
35>Compiling…
35>G4QGSBuilder.cc
37>G4VisCommandsViewerSet.cc
35>G4QGSPNeutronBuilder.cc
37>G4VisManager.cc
35>G4QGSPLundStrFragmProtonBuilder.cc
37>G4VisStateDependent.cc
35>G4QGSPPiKBuilder.cc
37>Generating Code…
37>E:\Geant4\geant4_10_05_p01\source\visualization\management\src\G4VisCommandsViewer.cc(1266,27): error C3536: ‘file’: cannot be used before it is initialized
37>Done building project “G4vis_management.vcxproj” – FAILED.

38>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
40>Generating Code…
38>Done building project “G4FR.vcxproj” – FAILED.

40>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
40>Done building project “G4VRML.vcxproj” – FAILED.
39>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
39>Done building project “G4Tree.vcxproj” – FAILED.

43>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
43>Done building project “G4visXXX.vcxproj” – FAILED.

45>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4FR.lib’
45>Done building project “G4GMocren.vcxproj” – FAILED.

42>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
42>Done building project “G4visHepRep.vcxproj” – FAILED.
44>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
44>Done building project “G4RayTracer.vcxproj” – FAILED.

41>LINK : fatal error LNK1104: cannot open file ‘…\BuildProducts\Debug\lib\G4vis_management.lib’
41>Done building project “G4OpenGL.vcxproj” – FAILED.

47>EXEC : CMake error : failed to create symbolic link ‘WIN32-VC’: operation not permitted

47>CMake Error at source/visualization/FukuiRenderer/cmake_install.cmake:49 (file):
47> file INSTALL cannot find
47> “E:/Geant4/geant4_10_05-build/BuildProducts/Debug/bin/G4FR.dll”.
47>Call Stack (most recent call first):
47> source/visualization/cmake_install.cmake:37 (include)
47> source/cmake_install.cmake:57 (include)
47> cmake_install.cmake:253 (include)
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: The command “setlocal
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: “C:\Program Files\CMake\bin\cmake.exe” -DBUILD_TYPE=Debug -P cmake_install.cmake
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: :cmEnd
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: :cmErrorLevel
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: exit /b %1
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: :cmDone
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
47>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(148,5): error MSB3073: :VCEnd” exited with code 1.
47>Done building project “INSTALL.vcxproj” – FAILED.
========== Build: 37 succeeded, 10 failed, 0 up-to-date, 0 skipped =========="

Please excuse the obnoxious length of my post. If I knew what information is redundant from the command window text, I would have removed it.

Thanks in advance.

Massimiliano

[1] http://geant4-resources.com/Geant4Tutorials/G4tutorial_files/installationGuide.pdf

Hello Massimiliano,

You could try to run as administrator both CMake-GUI and Visual studio. (Right click on shortcut and click “run as administrator”).

One issue I also faced in the past is that it would compile on Windows only in release mode. So you may change from Debug to Release or RelWithDebInfo (if it was in Debug in your try)

As last resort, you may also try to use Visual Studio 2015 or 2017 instead (note that the pre-compiled binaries given in the 10.5 download page are with VS 2017)

Good luck !

Hi David,

Thanks for the support and please forgive the ignorance with which I ask the following questions:

How do I change from Debug to Release? Is this something that can be done in the window below?

Massi

Hi Massimiliano,

After trying myself I think that the problem is that it is not set to the correct C++ standard by default, and so it cannot add the #include “filesystem” in the source file G4VisCommandsViewer.cc .

To fix it, you can try to add the option GEANT4_BUILD_CXXSTD=17 to the CMake-Gui (“Add entry”), and configure, generate and open the .sln in Visual Studio and build.
But then there is problem, it can’t find “binary_function” in the source file G4SmartVoxelStat.hh (" ‘binary_function’: is not a member of ‘std’ ") because it was removed for the C++ 17 standard. I will let you know when I find an easy solution.

Concerning the debug/release modes, you have two options. You can only keep Release (or whatever you want to keep) in CMAKE_CONFIGURATION_TYPES (that it to say, remove Debug, MinSizeRel, etc…), or inside Visual Studio, you can select the mode in a panel above (see attached screenshot). The available options are decided by what you give to CMAKE_CONFIGURATION_TYPES. But I don’t think that this is causing the errors you have now.

Warning (for later) : do not mix Geant4 libraries compiled in a given mode with Geant4 projects compiled with another mode (warning for Windows only, it is ok on Linux).

Good luck !

David, again thank you so much for your help.

I repeated everything but this time for Visual Studio 2017. In CMake-GUI I made sure to set the generator to Visual Studio 2017. Then, I opened Visual Studio 2017 in administrator mode, set the configuration to ‘Release’ and built the INSTALL project.

It built correctly (see screenshot below). Thank you!

I hope this post can help others who are encountering the same issues.

Massi

Great! Congratulations.

I confirm that Geant4 10.05.01 (Geant4-10.5.1) compiles successfully on Visual Studio 15 2017 (but not 2019) with the option by default GEANT4_BUILD_CXXSTD=11.