Clang Code Model doesn't work when using CMake
-
Hi.
I recently upgraded from Qt 6.4 to 6.5 and Qt Creator 10.0.2 to 11.0.0. One strange thing I noticed was that features provided by the Clang Code Model plugin were no longer working properly and I had loads of errors in front of me. Here's a screenshot:Strangely though, there wasn't any such error when using qmake as the build system. I understand this specific problem and the error related to Clang Code
Model had been discussed before, but hasn't it been solved in 2023? And for what reason does the problem persist only when using CMake? Is there anything I need to modify?Further note: First, you need to know in both cases programs are being built and run perfectly.
Second, I do know disabling Clang Code Model suppresses the errors, but I would lose countless others features as mentioned here. Hence, I don't consider this a solution. Furthermore, as mentioned here again, I could use the built-in code model via clangd, by going through Edit > Preferences > C++ > clangd, but I don't see any such option and thus believe the documentation is outdated. -
-
-
-
See https://bugreports.qt.io/browse/QTCREATORBUG-29450 for a similar report.
-
As I mentioned in the bugreport, the Clang Code Model plugin is using
clangd
which gets the project information via acompile_commands.json
file.Qt Creator writes it under
<build-dir>/.qtc_clangd/compile_commands.json
.You can compare the
compile_commands.json
file resulted from qmake and the one resulted from CMake and see what's going wrong with the CMake one.You can enable logging for Qt Creator by setting the environment variable
QT_LOGGING_RULES=qtc.clang*=true
before starting Qt Creator.You might get some hints why the CMake project is not working as expected.
-
Which CMake version are you using?
-
We found that that using CMake version 3.27.0 or 3.27.1 causes issues.
Please use an older version of CMake.
-
Indeed. I switched to the CMake version provided by Qt, deleted the build directory, re-ran "Build > Run CMake" and all was fixed.
Thanks everyone. -