特别是dataset和openGL等选定的特性确实开启了

时间:2022-06-12 05:42:08

因为有CMake自动化配置工具,在Windows平台上安置Geant4与Linux平台几乎同样便利。与使用Linux差此外是,官方更鼓励使用集成开发环境Visual Studio (VS)来编译安置。下面简单介绍一下。

系统环境: Windows10, Visual Studio 2017 (community), CMake 3.10, Geant4.10.04

1. 系统筹备

首先下载安置Visual Studio 2017 和最新版本CMake,笔者这里使用的是社区(community)版本的VS和3.10版本的 CMake.

(a) 安置完VS后需要添加C++工具包:选中 Tools > Get Tools and Features 安置必须的C++编译工具。

特别是dataset和openGL等选定的特性确实开启了

要验证C++工具包是不是正确安置了,可以选中 Tools > Visual Studio Command Prompt ,在VS中打开命令终端, 输入cl. 如果没有找到这个命令,那就是没有告成。

D:\>cl Microsoft (R) C/C++ Optimizing Compiler Version 19.12.25835 for x86 Copyright (C) Microsoft Corporation. All rights reserved. usage: cl [ option... ] filename... [ /link linkoption... ]

(b) CMake的安置过程中需要选择 Add CMake to the System PATH for all users.

特别是dataset和openGL等选定的特性确实开启了

2. 下载Geant4

到Geant4官网下载最新版本Geant4.10.04.zip, 解压到指定位置,譬如D盘,这样我们就有了文件夹D:\geant4_10_04, 我们再创建文件夹D:\geant4_10_04\build用来存放编译安置的姑且文件。

3. 编译

以下操纵需要简单的DOS命令。

打开Tools > Visual Studio Command Prompt, 进入D盘的build文件夹中运行CMake.

> D: > cd geant4_10_04/build > cmake -DCMAKE_INSTALL_PREFIX="D:\geant4_10_04" -DGEANT4_INSTALL_DATA=ON -DGEANT4_USE_OPENGL_WIN32=ON "D:\geant4_10_04"

注意:这里的openGL选项不是GEANT4_USE_OPENGL_X11,而是_WIN32结尾.

如果你看到类似输出,那就是告成了,出格是dataset和openGL等选定的特性确实开启了。

-- Configuring download of missing dataset G4NEUTRONXS (1.4) -- Configuring download of missing dataset G4PII (1.3) -- Configuring download of missing dataset RealSurface (2.1) -- Configuring download of missing dataset G4SAIDDATA (1.1) -- Configuring download of missing dataset G4ABLA (3.1) -- Configuring download of missing dataset G4ENSDFSTATE (2.2) -- The following Geant4 features are enabled: GEANT4_BUILD_CXXSTD: Compiling against C++ Standard ‘11‘ GEANT4_USE_OPENGL_WIN32: Build OpenGL driver with Win32 support -- Configuring done -- Generating done -- Build files have been written to: D:/geant4_10_04/build

运行以下命令编译Geant4.

> cmake --build . --config Release

如果输出功效有类似结尾,那么应该没有问题。

FinalizeBuildStatus: Deleting file "Win32\Release\ALL_BUILD\ALL_BUILD.tlog\unsuccessfulbuild". Touching "Win32\Release\ALL_BUILD\ALL_BUILD.tlog\ALL_BUILD.lastbuildstate". Done Building Project "D:\geant4_10_04\build\ALL_BUILD.vcxproj" (default targets). Build succeeded. 0 Warning(s) 0 Error(s) 4. 安置

> cmake --build . --config Release --target install

输出功效应该类似这样结尾:

-- Installing: D:/geant4_10_04/include/Geant4/G4VisTrajContext.hh -- Installing: D:/geant4_10_04/include/Geant4/G4VisTrajContext.icc FinalizeBuildStatus: Deleting file "Win32\Release\INSTALL\INSTALL.tlog\unsuccessfulbuild". Touching "Win32\Release\INSTALL\INSTALL.tlog\INSTALL.lastbuildstate". Done Building Project "D:\geant4_10_04\build\install.vcxproj" (default targets). Build succeeded. 0 Warning(s) 0 Error(s)

以上已经安置完成,但是在实际使用前还要设置环境变量。

5. 设置环境变量

如何添加环境变量请自行百度。

PATH 追加 D:\geant4_10_04\bin G4ENSDFSTATEDATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4ENSDFSTATE2.2 G4LEDATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4EMLOW7.3 G4LEVELGAMMADATA D:\geant4_10_04\share\Geant4-10.4.0\data\PhotonEvaporation5.2 G4SAIDXSDATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4SAIDDATA1.1 G4NEUTRONHPDATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4NDL4.5 G4NEUTRONXSDATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4NEUTRONXS1.4 G4PIIDATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4PII1.3 G4RADIOACTIVEDATA D:\geant4_10_04\share\Geant4-10.4.0\data\RadioactiveDecay5.2 G4REALSURFACEDATA D:\geant4_10_04\share\Geant4-10.4.0\data\RealSurface2.1 G4ABLADATA D:\geant4_10_04\share\Geant4-10.4.0\data\G4ABLA3.1

示例example/basic/B1的测试