ubuntu20.4安装配置geant4和root
1.下载需要的软件包和数据包
- 下载root
https://root.cern/install/all_releases
- 下载geant4
https://geant4.web.cern.ch/download/all
2.准备安装文件
- 在home目录下面创建一个geant4的文件夹
- 打开geant4文件夹,在里面创建一个file的文件夹
- 将下载好的14个文件拖动到这个文件夹(home目录下的/geant4/file/)下
- 右击终端打开
cd ~
- 将刚刚传入的文件移动到opt目录下
sudo mv geant4/ /opt/
- 进入下载的文件的文件夹目录
cd /opt/geant4/file/
- 移动下载的geant4安装包到上级目录
sudo mv /opt/geant4/file/geant4*.tar.gz ..
- 返回上一级
cd ..
- 解压
sudo tar -zxvf geant4*.tar.gz
- 删除安装包
sudo rm -rf geant4*.tar.gz
3.安装依赖
- 安装依赖工具
sudo apt install curl g++ libgl1-mesa-dev cmake libx11-dev libxext-dev libxtst-dev libxrender-dev libxmu-dev libxmuu-dev libhdf5-serial-dev hdf5-tools libexpat1 libexpat1-dev build-essential -y
- 安装qt5
sudo apt install qt5* -y
- 创建两个文件夹
mkdir geant4-install
mkdir geant4-build && cd geant4-build
4.安装geant4
sudo cmake -DCMAKE_INSTALL_PREFIX=/opt/geant4/geant4-install \
-DGEANT4_USE_OPENGL_X11=ON \
-DGEANT4_USE_RAYTRACER_X11=ON \
-DGEANT4_USE_QT=ON \
-DGEANT4_BUILD_MULTITHREADED=ON \
/opt/geant4/geant4-v11.1.1
- 多核编译(ps:-jn表示应用的电脑逻辑处理器数)
sudo make -j6
- 进行安装
sudo make install -j6
- 设置环境变量
echo "source /opt/geant4/geant4-install/bin/geant4.sh" >> ~/.bashrc
5.安装geant4的数据包
- 进入下载的文件的文件夹目录
cd /opt/geant4/file/
- 创建data文件夹
sudo mkdir -p /opt/geant4/geant4-install/share/Geant4/data
- 移动数据包到geant4的安装目录下
sudo mv G4*.tar.gz /opt/geant4/geant4-install/share/Geant4/data
- 然后在data文件夹下批量解压
cd /opt/geant4/geant4-install/share/Geant4/data
sudo ls *.tar.gz | sudo xargs -n1 tar xzvf
- geant4的数据包已经安装完成,删除数据包
sudo rm -rf G4*.tar.gz
- 使环境变量生效
source ~/.bashrc
6.安装root
- 右击终端打开
- 进入下载的文件的文件夹目录
cd /opt/geant4/file/
- 解压即可使用 - 在Ubantu系统中解压的命令
sudo tar -zxvf root*.tar.gz
- 移动到opt目录下
sudo mv root /opt/
- 删除安装包
sudo rm -rf root*.tar.gz
- 配置环境变量(ps:之后每次想要用root的时候可以直接使用,更加方便)
echo "source /opt/root/bin/thisroot.sh" >> ~/.bashrc
- 使环境变量生效
source ~/.bashrc
- 验证root
root
7.验证安装
- 右击终端打开
- 建立工作路径
mkdir ~/geant4_ws && cd ~/geant4_ws
- 将官方例子复制到工作路径里面
cp -r /opt/geant4/geant4-install/share/Geant4/examples ~/geant4_ws
cp -r ~/geant4_ws/examples/basic/B1 ~/geant4_ws
cd B1
mkdir build && cd build
- 下面的命令cmake后面是空格加两个点(表示用上级目录进行cmkae)
cmake ..
- 出错的话执行
source ~/.bashrc
- 编译运行
make -j6
./exampleB1
8.在VS Code中配置Geant4
- 进入官网下载VS Code
- 下载很慢可以将下载链接中的"/stable"前面的域名换成"vscode.cdn.azure.cn"即可实现加速下载
- 进入下载目录在终端打开进行安装
sudo dpkg -i code*.deb
- 安装好后打开VS Code
- 安装插件Chinese中文简体、C/C++、CMake Tools
- 在VS Code中打开复制的B1实例文件夹
- 按住Ctrl+Shift+P,搜索框中输入c++,点击"编辑配置(JSON)"
- 修改json文件内容如下
{
"configurations": [
{
"name": "Linux",
"browse": {
"path": [
"${workspaceFolder}/src", //链接source
"${workspaceFolder}/include", //链接include
"/opt/root/include", //链接root
"/opt/geant4/geant4-install/include/Geant4" //链接Geant4头文件
],
"limitSymbolsToIncludedHeaders": true
},
"includePath": [
"${workspaceFolder}/src", //链接source
"${workspaceFolder}/include", //链接include
"/opt/root/include", //链接root
"/opt/geant4/geant4-install/include/Geant4" //链接Geant4头文件
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
然后就能运行了。
9、在Clion中配置Geant4
- 安装中文插件
- 打开-->CMakeLists.txt-->作为项目打开
- 默认是DeBug配置,先添加Release配置项再删除DeBug配置项
- 部署时在CMake选项中指定Geant4安装目录
-D Geant4_DIR:PATH=/opt/geant4/geant4-install/lib/cmake/Geant4
- 在编辑配置中设置环境变量指定库文件
LD_LIBRARY_PATH=/opt/geant4/geant4-install/lib
然后就能运行了。