Gean4的安装
路径问题
在WSL中安装时,需注意Geant4的安装路径是否:
- 路径过长
- 路径中包含中文
- 路径中包含空格 " "
- 路径中包含别的特殊字符
使用anaconda安装
参考官方手册,使用anaconda安装的命令:
conda create -c conda-forge --name <my-environment> geant4
讯享网
注意,conda中启用geant4的命令是:
讯享网conda activate <my-environment>
conda安装的example/B1的位置在 "~/.conda/envs/geant4/share/Geant4-10.7.2/examples/basic/B1"可以通过如下命令找到:
find ~/.conda/env -name "B1"
讯享网Could NOT find EXPAT: Found unsuitable version "2.2.9", but required is at least "2.4.1" (found /usr/lib/x86_64-linux-gnu/libexpat.so) Call Stack (most recent call first):
在WSL中使用conda安装Geant4(不推荐)
有个异常曲折的方法, 参考这篇和这篇,将wsl的ubuntu升级到ubuntu21.10,然后安装sudo apt-get install libfreetype6-dev就好了。详细如下:
先给ubuntu换apt源,此过程不赘述。接着更新系统:
sudo apt update && sudo apt upgrade # 确保更新到最新 vim /etc/update-manager/release-upgrades # 编辑该文件使得最后一行为normal,而不是lts
讯享网比如,将/etc/update-manager/release-upgrades修改为: ```bash # Default behavior for the release upgrader. [DEFAULT] # Default prompting behavior, valid options: # # never - Never check for a new release. # normal - Check to see if a new release is available. If more than one new # release is found, the release upgrader will attempt to upgrade to # the release that immediately succeeds the currently-running # release. # lts - Check to see if a new LTS release is available. The upgrader # will attempt to upgrade to the first LTS release available after # the currently-running one. Note that this option should not be # used if the currently-running release is not itself an LTS # release, since in that case the upgrader won't be able to # determine if a newer release is available. Prompt=normal ```
然后开始更新ubuntu的大版本
sudo do-release-upgrad
讯享网sudo apt-get install libfreetype6-dev # 安装编译geant4的依赖。
conda create -c conda-forge --name <my-environment> geant4 # 这里<my-environment>可以写"geant4" conda activate <my-environment> cd ~/.conda/envs/<my-environment>/share/Geant4-10.7.2/examples/basic/B1/
效果如下图所示:

讯享网
Geant4的使用
主要是遇到了关于QT的问题,有很多:

编译时错误
/usr/lib/x86_64-linux-gnu/libSM.so: undefined reference to `uuid_generate@UUID_1.0’
尝试运行下面命令以解决,
讯享网conda install -c conda-forge xorg-libsm
或者,最简单的方法:
- 删除掉Anaconda自带的过期库文件
- 用系统的库文件替换之
export condapath=`whereis anaconda3` # ${condapath:10} 表示安装anaconda3的位置 sudo mv ${condapath:10}/lib/libuuid.so.1 ${condapath:10}/lib/back_libuuid.so.1 sudo ln -s /lib/x86_64-linux-gnu/libuuid.so.1 ${condapath:10}/lib/libuuid.so.1
/usr/bin/ld: /home/wsl2/Application/geant4-v11.0.0/lib/libG4tasking.so: undefined reference to `PTL::TaskRunManager::Initialize(unsigned long)’
该问题互联网上暂时无解。。。。
如果有大佬能解决该问题,还请不吝赐教23333
重装WSL即可解决
运行时错误
01 error while loading shared libraries: libQt5Core.so.5: cannot open shared object file: No such file or directory
解决方案:
讯享网sudo strip --remove-section=.note.ABI-tag /usr/lib64/libQt5Core.so.5 # 或者 sudo strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5
参考:
https://askubuntu.com/questions//ubuntu-18-4-libqt5core-so-5-cannot-open-shared-object-file-no-such-file-or-dir
https://github.com/dnschneid/crouton/wiki/Fix-error-while-loading-shared-libraries:-libQt5Core.so.5
02 QXcbConnection: XCB error: 170 (Unknown), sequence: 170, resource id: 90, major code: 146 (Unknown), minor code: 20 Segmentation fault (core dumped)
可以通过键入如下命令修复:
export LIBGL_ALWAYS_INDIRECT=0
参考:
https://answers.ros.org/question//qxcb-connection-xcb-error-170/
LIBGL_ALWAYS_INDIRECT 指令是用来干什么的?
03 QStandardPaths: XDG_RUNTIME_DIR not set
可以通过键入如下命令修复
讯享网export XDG_RUNTIME_DIR=/some/directory/you/specify
其实就是将这个XDG_RUNTIME_DIR设置为某个你拥有权限的目录。任何你拥有权限的目录都行。
参考:
https://dev.to/winebaths/getting-up-and-running-with-the-windows-subsystem-for-linux-8oc
04 Errors linking blit shader:
Could not create shader of type 2.
Warning: “” failed to compile!
重装Geant4可以解决,没找到别的办法…
05 No protocol specified
qt.qpa.xcb: could not connect to display 你主机的ip.1:0.0
这是因为WSL2在开启x服务器时要求勾选上 No Access Control

注意,WSL2和WSL1可以直接使用localhost不一样,WSL2的display应当使用主机的IP,可以通过如下命令获得:
cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " " # 查看主机ip host_ip=$(cat /etc/resolv.conf |grep "nameserver" |cut -f 2 -d " ") export DISPLAY=$host_ip:0.0
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/117681.html