Use of undeclared identifier 'QT_VERSION_PATCH'

Geant4 Version: geant4-v11.2.0
Operating System: MacOS Sonoma 14.2.1 (23C71)
Apple clang version 15.0.0 (clang-1500.
Target: x86_64-apple-darwin23.2.0
Thread model: posix
CMake Version: 3.28.3

I have one working installation on my Mac without visualisation enabled and it works fine.
I am trying to have another build with QT enabled so that I can visualise my detector. The configuration and build and installation of G4 were done successfully without any errors. But I get errors when running the test example B1.

I used ccmake and set the following options when building geant4.

QT_DIR /usr/local/opt/qt@5/lib/cmake/Qt5
Qt53DCore_DIR /usr/local/opt/qt@5/lib/cmake/Qt53DCore
Qt53DExtras_DIR /usr/local/opt/qt@5/lib/cmake/Qt53DExtras
Qt53DInput_DIR /usr/local/opt/qt@5/lib/cmake/Qt53DInput
Qt53DLogic_DIR /usr/local/opt/qt@5/lib/cmake/Qt53DLogic
Qt53DRender_DIR /usr/local/opt/qt@5/lib/cmake/Qt53DRender
Qt5Core_DIR /usr/local/opt/qt@5/lib/cmake/Qt5Core
Qt5Gamepad_DIR /usr/local/opt/qt@5/lib/cmake/Qt5Gamepad
Qt5Gui_DIR /usr/local/opt/qt@5/lib/cmake/Qt5Gui
Qt5Network_DIR /usr/local/opt/qt@5/lib/cmake/Qt5Network
Qt5OpenGL_DIR /usr/local/opt/qt@5/lib/cmake/Qt5OpenGL
Qt5Widgets_DIR /usr/local/opt/qt@5/lib/cmake/Qt5Widgets
Qt5_DIR /usr/local/opt/qt@5/lib/cmake/Qt5
X11_xcb_xkb_INCLUDE_PATH /usr/local/include

ccmake …/B1 does not give any error, but running the make command gives the following errors.

In file included from /usr/local/opt/qt@5/lib/QtCore.framework/Headers/qglobal.h:1301:
/usr/local/opt/qt@5/lib/QtCore.framework/Headers/qtypeinfo.h:240:1: error: use of undeclared identifier ‘QT_VERSION_MAJOR’
/usr/local/opt/qt@5/lib/QtCore.framework/Headers/qtypeinfo.h:232:21: note: expanded from macro ‘Q_DECLARE_MOVABLE_CONTAINER’
isStatic = (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)),
/usr/local/opt/qt@5/lib/QtCore.framework/Headers/qglobal.h:57:42: note: expanded from macro ‘QT_VERSION’

There are more errors but they are essentially a repeat of what I have pasted above. If more information is needed, I can attach the full output as a text file.
I remember encountering this problem earlier but I do not recall how I solved it. Any help would be greatly appreciated.

I too am on macOS Sonoma, on 14.3.1.

Qt and X11 sometimes have problems co-existimg, depending on which X11 and how many (Quartz, hone brew,…). Switch off X11 options.

Also, Qt5 and Qt6 have problems coexisting. If you have Qt6 on your machine, let us know and we will elaborate.

I turned off X11 and rebuilt it but still got the same errors.
PS: I do not have qt6 installed. I do have qt5, qt@5 and qt4 on my machine and qt@5 is being used by geant4.

It’s possible that there’s a conflict arising between the various versions of Qt you have installed. Could you:

  1. post the paths under which the qt5 and qt4 you mention are installed (and which exact versions these are)
  2. Post the result of make -j1 VERBOSE=1 here in a text file

please? The first should help to determine if there is a clash of include paths, and the latter confirm it of so.

  1. The paths of all directories that have qt in their name are as follows:

  2. I first configured B1 using

ccmake …/B1

and then did make


The results is in the following file:
terminal_output.txt (17.4 KB)

I wish to add that when I do a new build, I delete the build and the install directories and then redo the building process from the source code. I have not used ‘make clean’ yet and wondered if that would help.

Thanks for the info! Unfortunately I can’t see anything obviously wrong with the compile command - it pretty much matches what I get on a local build except for the arm64 flags (I’m not on an Intel machine). I can only think of three things to check:

  1. Run:

    find /opt/homebrew/opt/qt@5/ -type f -exec grep -H "QT_VERSION_MAJOR" {} \;

    and post the output here.

  2. Run brew list --versions | grep qt and post the output here

  3. Find the file named Geant4PackageCache.cmake under /Users/aneesha/geant4/geant4-v11.2.0-install-qt and post its contents here.

1. find: /opt/homebrew/opt/qt@5/: No such file or directory

qt-legacy-formula 999.0.0
qt-webkit@2.3 2.3.4_1
qt@4 4.8.7_6
qt@5 5.15.13
  1. I copied the content of Geant4PackageCache.cmake to a .txt file to be able to upload it here.
    Geant4PackageCache.txt (3.3 KB)

Ah, sorry, that should have been:

find /usr/local/opt/qt@5/ -type f -exec grep -H "QT_VERSION_MAJOR" {} \;

The other two bits looks fine so far.

The output of the command is as follows:

Binary file /usr/local/opt/qt@5//bin/qdbuscpp2xml matches
Binary file /usr/local/opt/qt@5//bin/moc matches
/usr/local/opt/qt@5//lib/QtCore.framework/Versions/5/Headers/qconfig.h:#define QT_VERSION_MAJOR 5
/usr/local/opt/qt@5//lib/QtCore.framework/Versions/5/Headers/qglobal.h:#define QT_VERSION      QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH)
/usr/local/opt/qt@5//mkspecs/modules/qt_lib_bootstrap_private.pri:QT.bootstrap_private.DEFINES = QT_BOOTSTRAP_LIB QT_VERSION_STR=\'\"5.15.13\"\' QT_VERSION_MAJOR=5 QT_VERSION_MINOR=15 QT_VERSION_PATCH=13 QT_BOOTSTRAPPED QT_NO_CAST_TO_ASCII

Thanks again, but I’m nearly at a complete loss to explain what the problem could be. The includes look fine, and the order should be fine. The only remaining things to try are:

  1. Run brew doctor and fix any issues
  2. Check that none of the qt formulae are linked, i.e. run brew unlink qt@4, brew unlink qt@5. Additionally check if there are any QtCore or qt headers left in /usr/local/include.
  3. Reinstall the qt@5 formula just in case something has got corrupted/permissions
  4. When building exampleB1 you could run ccmake and then edit CMAKE_CXX_FLAGS to add the -v flag. That will make the compile output very verbose and should show exactly what’s included and from where.

I did steps 3 and 1 and there were a couple of warnings after step 1 that I cleared up. After that, I rebuilt it (without deleting the already built geant I had) and ran the example B1 again. This time, the build was completed successfully. The file ./exampleB1 showed no warnings or errors but it also did not display the visualization window.
I have attached the first few lines of the output here:
B1 output.txt (2.4 KB)
Do you have any suggestions on figuring out if qt is enabled?

I appreciate all the help you are providing. Thank you.

UPDATE: I switched off GDML and multithreading and built G4 with only qt ON and the visualization worked! I do not know if GDML/multithreading and QT are incompatible in some way or not.

Hi Aneesha

The registered graphics systems (about line 12 of your log) show me Geant4 (the whole of Geant4, not just your app) has been built without visual graphics. (It shows only file-writing graphics systems.) So go back and rebuild with graphics options as described in the Installation Guide. I imagine you will want to add

-DGEANT4_USE_QT=ON -DCMAKE_PREFIX_PATH="$(brew --prefix qt@5)" 

to your cmake options. (Don’t forget to remove CmakeCache.txt - it remembers the past!!)

At this point you might get the same problem as before. Please follow Ben’s advice and run the brew doctor and unlink qt, etc. And if all fails, run with -v and post us the output.

Good luck

Thank you for your response. I have a quick question.
If I have G4 running on my Mac with visualization, could you please tell me what file I am supposed to view to find out the settings that were used when building G4?

You can run geant4-config --features to print a list of enabled features.

Thank you. I get the following output after running geant4-config --features

Known Features:

My installation seems to be working fine today in terms of the visualization.
@allison Can you please help me interpret this result? Thank you.

You want me to interpret this result? My interpretation is: it’s working.

That’s great. Thanks for letting us know.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.