M1 MacでGeant4を使う
はじめに
M1 MacでGeant4をGEANT4_USE_QT=ON
でコンパイルしようとしたらハマりました。
Qtのインストール
Geant4は様々なvisualization driverがありますが、この資料によると「The most recent : Qt + OpenGL」とのことなので、以下のようにQtをHomebrewでインストールしました。
$ brew install qt
インストールされたのはQt 6でした。今思えば、これをこのままにしておいたことが間違い。Geant4がサポートするのはQt 5なので、さらに、
$ brew install qt@5
としました。Qt 5はkeg-onlyなので、/opt/homebrew/include
等にシンボリックリンクが作成されませんでした。
Geant4のコンパイル
ソースはGithubからもってきました。
$ git clone https://github.com/Geant4/geant4.git $ mkdir build $ cd build $ cmake \ -DGEANT4_BUILD_MULTITHREADED=ON \ -DGEANT4_INSTALL_DATA=ON \ -DGEANT4_USE_QT=ON \ -DGEANT4_USE_OPENGL_X11=ON \ -DGEANT4_USE_GDML=ON \ -DGEANT4_USE_XM=ON \ -DGEANT4_USE_SYSTEM_CLHEP=ON \ -DGEANT4_USE_SYSTEM_EXPAT=ON \ -DGEANT4_USE_SYSTEM_ZLIB=ON \ -DCMAKE_INSTALL_PREFIX=/opt/homebrew/Cellar/geant4/11.0.0.beta \ ../geant4
とすると、
Could not find a package configuration file provided by "Qt5Core" with any of the following names: Qt5CoreConfig.cmake qt5core-config.cmake Add the installation prefix of "Qt5Core" to CMAKE_PREFIX_PATH or set "Qt5Core_DIR" to a directory containing one of the above files. If "Qt5Core" provides a separate development package or SDK, be sure it has been installed.
と表示されたので、Qt 5を認識させるためにCMAKE_PREFIX_PATH
を加えました。
$ rm CMakeCache.txt $ cmake \ -DGEANT4_BUILD_MULTITHREADED=ON \ -DGEANT4_INSTALL_DATA=ON \ -DGEANT4_USE_QT=ON \ -DGEANT4_USE_OPENGL_X11=ON \ -DGEANT4_USE_GDML=ON \ -DGEANT4_USE_XM=ON \ -DGEANT4_USE_SYSTEM_CLHEP=ON \ -DGEANT4_USE_SYSTEM_EXPAT=ON \ -DGEANT4_USE_SYSTEM_ZLIB=ON \ -DCMAKE_INSTALL_PREFIX=/opt/homebrew/Cellar/geant4/11.0.0.beta \ -DCMAKE_PREFIX_PATH=/opt/homebrew/opt/qt5 \ ../geant4
こうすると、Qt5Core_DIR
等が/opt/homebrew/opt/qt5/lib/cmake/Qt53DCore
などと設定されたので、Qt 6が入ったままでも問題ないだろうと思っていました。
しかし、
$ make -j4
とすると、
/***/geant4/src/main/source/interfaces/basic/include/G4UIQt.hh:55:7: error: definition of type 'QStringList' conflicts with type alias of the same name class QStringList; ^ /opt/homebrew/include/QtCore/qcontainerfwd.h:64:7: note: 'QStringList' declared here using QStringList = QList<QString>;
とのエラーが。ここで(ちゃんと書いてあるのに)/opt/homebrew/include/QtCore
を参照していることに気づかず、かなり時間をロスしました…
エラーの原因は/opt/homebrew/include
以下にあるQt 6のファイル(シンボリックリンク)なので、/opt/homebrew/include
を参照することになりそうな-DGEANT4_USE_SYSTEM_*
等を省いてcmake
を実行しました。
$ rm CMakeCache.txt $ cmake \ -DGEANT4_BUILD_MULTITHREADED=ON \ -DGEANT4_INSTALL_DATA=ON \ -DGEANT4_USE_QT=ON \ -DGEANT4_USE_GDML=ON \ -DCMAKE_INSTALL_PREFIX=/opt/homebrew/Cellar/geant4/11.0.0.beta \ -DCMAKE_PREFIX_PATH=/opt/homebrew/opt/qt5 \ ../geant4
make
します。
$ make -j4
… [100%] Built target G4physicslists
コンパイルできたのでインストール。
$ make install
examples/basic/B1をコンパイル&実行してみた
$ pushd /opt/homebrew/Cellar/geant4/11.0.0.beta/bin && \ source geant4.sh && \ popd $ mkdir ../build_example $ cd ../build_example $ cmake ../geant4/examples/basic/B1 $ make $ ./exampleB1
できました🎉
おわりに
$ brew unlink qt
とした方がいいかも。