I am trying to run the Analog Clock example from the Widgets Examples section of the Qt web site. (If you try to run that file, note that the sample code is missing a closing brace at the very end of the file.)
I was able to build and run the file successfully using cmake (after a minor kluge because one of the statements requires Qt 6.6, but Ubuntu will only load 6.2.4).
For simple, one source file projects, I'd prefer using plain g++ rather than a complex build system. Cmake does in fact default to g++.
My source file contains the line:
#include <QWidget>
My g++ command line is:
g++ -std=c++23 -I/usr/include/x86_64-linux-gnu/qt6:/usr/include/x86_64-linux-gnu/qt6/QtWidgets analogclock.cpp
The error I get is:
analogclock.cpp:6:10: fatal error: QWidget: No such file or directory
6 | #include <QWidget>
| ^~~~~~~~~
The QtWidgets directory is there, and it does contain the QWidget file. (I need the first component of the -I list to avoid a different error.)
I haven't used g++ for a while, so clearly I am doing something wrong. Any help, please.
Edit: the link provided by @Laughing Out Clouds does not address the issue. All of the answers and comments in that link use qmake and/or a project file. Not a single solution addresses a pure g++ approach. I already know I can run the file with cmake with its byzantine requirements.
Your
g++commandline contains the invalid-Ioption:You cannot give multiple directory arguments to the the
-Ioption by separating them with:.g++thinks you are specifying a single directory called:and gives no error. This is a valid directory name on your filesystem and if you add
-vto your commandline to get a verbose build log, you will see it reported that this nonexistent directory is ignored. If you wish to specify multiple include paths, use one-Ioption for each, giving them in the search priority order that you want: