QtCreator reports lots of headers as "not found"
-
Hi!
I'm using the latest version of QtCreator (10.0.1) with Qt 5.15.2 for Windows together with Visual Studio 2022.
I have been developing and maintaining a library for 6 years now. Yesterday, I rebuilt the latest version as well as some apps that rely on it. Everything worked as usually: no problems at all.
This morning I reopened the project in QtCreator to analyze one of the methods in one of the classes this library includes. The problem is that now, when I open any of the files it contains, lots of warnings related to some inclusion files show up. They all refer to headers ending in .h, such as <string.h> or <math.h>. The message is that the header cannot be found.
This is not a problem related to the visual aids offered by QtCreator, that is, is not just a message shown by the analyzer to help you to correct your mistakes as soon as possible. On the contrary, if I try to build the library, I get the same errors stating that lots of header files cannot be found.
Since I rely on Visual Studio 2022 I copied some of the .hpp and .cpp files that do not need any Qt libraries and created a new project using VS. There, the same files compile flawlessly.
Therefore, it is not a problem of the underlying compiler, but related to Qt itself. Below you may see a snapshot of QtCreator showing one of the hundreds of warnings to illustrate the situation.
Any ideas? Should I try to reinstall Qt? I have to say that I made no changes to Qt since yesterday, and then it worked perfectly...
By the way: I'm not sure whether this subforum is the right place for this post. Excuse me, please, if I should have posted elsewere.
Thanks!
-
C Christian Ehrlicher moved this topic from General and Desktop on
-
seems like your path variable was messed up somehow. Maybe update of OS, MSVC ?
I think you're using MSVC compiler? So reinstalling QtCreator should not make any differences.
Maybe reinstall MSVC, Windows Kits, will fix this.
Or you manually patch it in the project settings:
-
@bleriot13
alternatively, try removing the settings file of QtCreator,https://doc.qt.io/qtcreator/creator-quick-tour.html#location-of-settings-files
I think that file is actually persistent and does not get automatically resolved with a reinstall
or give it a (temporary) different location for the settings
-settingspath <path>
or
-temporarycleansettings, -tcsif that fixes it, that the settings are at fault
-
@bleriot13 on start of QtCreator
see the command line option I added in my previous post
-
@J-Hilk Hi.
I don't know how did you get the window with that environment variables. Are the ones set by Windows? Or, on the contrary, these are handled by Qt? I mean: if I check my Windows variables I have no INCLUDE nor LIB variables... even after reinstalling MSVC, so I guess that these correspond to some option available in QtCreator. Can you tell me if I'm right and, if so, how to get to that window????
I'm asking that because it seems that reinstalling (well, REPAIRING) MSVC does not work.
Just one extra question: the command line switches you mention correspond to some tool,I guess. I assume that you mean that I should start qtcreator from the command line passin any of that arguments, is this so?
Thanks you! Now I leave. No more interaction until tomorrow...
-
You should run the Visual Studio Installer and do any updates that it thinks it needs to be done.
By running
cmd.exe
and then:call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat"
(adjust to your local setup
C:\Program Files (x86)
->C:\Program Files
, andBuildTools
->Professional
|Community
|Enterprise
)You will then get the environment where you can run the Visual C++ compilers -
cl.exe
.In my case it looks like:
********************************************************************** ** Visual Studio 2022 Developer Command Prompt v17.6.0 ** Copyright (c) 2022 Microsoft Corporation ********************************************************************** [vcvarsall.bat] Environment initialized for: 'x64'
With:
set | findstr /i ^^INCLUDE=
You can then see the paths that the compiler will look after files.
Qt Creator when it registers the Visual C++ compilers runs the same
vcvars64.bat
to collect the environment variables.With
Ctrl+Shift+F12
(Tools -> Debug Qt Creator -> Inspect C++ Code Model) you can have some information about what Qt Creator considers to be available.I have
math.h
under:"c:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\ucrt\math.h"
and this path is part of the
INCLUDE
environment variable from above.On Windows setting up a working Visual C++ compiler can be a bit complicated. More than just unpacking an archive.
-
Hi once more.
I'm on the verge of desperation.
Following a mix of the advice given by all of you I have gone through the steps below:
- Updated MSVC using the MSVC installer.
- Uninstalled Qt completely.
- Deleted the Qt settings in %appdata%\QtProject and %localappdata%\QtProject (not the contents of these folders but the folders themselves, so no trace of settings remained).
- Removed all temporary files using Bleachbit.
- Cleaned the registry using Glarysoft Registry Cleaner.
- Restarted the computer.
- Installed Qt from scratch.
The problem persists.
If I show the paths used by Qt using Tools -> Debug Qt Creator -> Inspect C++ Code Model I get the following:
The red rectangle points to the paths that seem to indicate include directories. There, there's no trace of the actual path where one of the missing header files (math.h, for instance) is located:
C:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0\ucrt
a folder which is the same as the one given by cristian-adam.
My last hope is to UNINSTALL everything (MSVC, Qt) and start again. This is what I'm going to do right now. If this doesn't work, I don't know what else can I do.
-
Big uff @bleriot13 ! It shouldn't be that hard to get a working MSVC installation.
Alternatively you could try a different way of installing Visual Studio, via a package manager (Chocolatey):
$ choco install visualstudio2022buildtools $ choco install windows-sdk-11-version-22H2-all
Then at the end I start the "Visual Studio Installer" from start menu and selected "Desktop Development with C++".
I only need Visual Studio
BuildTools
and notCommunity
. -
No joy.
This time I have uninstalled everything, cleaned preferences, registry and temporary files.
The result is exactly the same. However, there's something I have noticed that is related to the MSVC compiler.
If you open an "x64 Native Tools Command Prompt" using the MSVC 2022 entry in Windows Start menu, the vcvars64.bat batch file is automatically executed. Therefore, issuing the "SET" command lists the environment variables set in such a way that the compiler (cl.exe) may work properly.
Well, just after installing MSCV 2022 from scratch and before installing Qt, I opened the said command prompt and typed "set". The result is shown below:
ALLUSERSPROFILE=C:\ProgramData APPDATA=C:\Users\cttc\AppData\Roaming CommandPromptType=Native CommonProgramFiles=C:\Program Files\Common Files CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files CommonProgramW6432=C:\Program Files\Common Files COMPUTERNAME=LTJANAVARRO ComSpec=C:\WINDOWS\system32\cmd.exe DevEnvDir=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\ DriverData=C:\Windows\System32\Drivers\DriverData EFC_4820=1 ExtensionSdkDir=C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs EXTERNAL_INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include Framework40Version=v4.0 FrameworkDir=C:\Windows\Microsoft.NET\Framework64\ FrameworkDir64=C:\Windows\Microsoft.NET\Framework64\ FrameworkVersion=v4.0.30319 FrameworkVersion64=v4.0.30319 GDAL_DATA=C:\Program Files\PostgreSQL\13\gdal-data GEOSERVER_DATA_DIR=C:\ProgramData\GeoServer GEOSERVER_HOME=C:\Program Files\GeoServer HOMEDRIVE=C: HOMEPATH=\Users\cttc INCLUDE=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\ATLMFC\include;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Auxiliary\VS\include JAVA_HOME=C:\Program Files\Java\jdk-11 LIB=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\lib\x64 LIBPATH=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\ATLMFC\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\lib\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\lib\x86\store\references;C:\Windows\Microsoft.NET\Framework64\v4.0.30319 LOCALAPPDATA=C:\Users\cttc\AppData\Local LOGONSERVER=\\LTJANAVARRO NUMBER_OF_PROCESSORS=8 OneDrive=C:\Users\cttc\OneDrive - Centre Tecnol•gic de Telecomunicacions de Catalunya OneDriveCommercial=C:\Users\cttc\OneDrive - Centre Tecnol•gic de Telecomunicacions de Catalunya OPENCV_DIR=C:\Users\cttc\ODjnavarro\jnavarro\Dev2\opensource_libraries\opencv3 OS=Windows_NT Path=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\bin\HostX64\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\VCPackages;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer;C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\bin\Roslyn;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools\x64;C:\Program Files\Microsoft Visual Studio\2022\Community\Team Tools\Performance Tools;C:\Program Files\Microsoft Visual Studio\2022\Community\\MSBuild\Current\Bin\amd64;C:\Windows\Microsoft.NET\Framework64\v4.0.30319;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\;C:\Users\cttc\ODjnavarro\jnavarro\Dev2\ADAtools\installer\deployment\bin;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\dotnet\;C:\Users\cttc\AppData\Local\Microsoft\WindowsApps;C:\Users\cttc\AppData\Local\Programs\MiKTeX\miktex\bin\x64\;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\CMake\bin;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\CommonExtensions\Microsoft\CMake\Ninja;C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\Linux\bin\ConnectionManagerExe;C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC PGPASSFILE=%APPDATA%\postgresql\pgpass.conf Platform=x64 POSTGIS_ENABLE_OUTDB_RASTERS=1 POSTGIS_GDAL_ENABLED_DRIVERS=GTiff PNG JPEG GIF XYZ DTED USGSDEM AAIGrid PROCESSOR_ARCHITECTURE=AMD64 PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 142 Stepping 12, GenuineIntel PROCESSOR_LEVEL=6 PROCESSOR_REVISION=8e0c ProgramData=C:\ProgramData ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) ProgramW6432=C:\Program Files PROJ_LIB=C:\Program Files\PostgreSQL\13\share\contrib\postgis-3.1\proj PROMPT=$P$G PSModulePath=C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules PUBLIC=C:\Users\Public PYTHONPATH=C:\Users\cttc\jnavarro\Dev2\python SESSIONNAME=Console SystemDrive=C: SystemRoot=C:\WINDOWS TEMP=C:\Users\cttc\AppData\Local\Temp TMP=C:\Users\cttc\AppData\Local\Temp USERDOMAIN=LTJANAVARRO USERDOMAIN_ROAMINGPROFILE=LTJANAVARRO USERNAME=janavarro USERPROFILE=C:\Users\cttc VCIDEInstallDir=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\IDE\VC\ VCINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\ VCPKG_ROOT=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\vcpkg VCToolsInstallDir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.36.32532\ VCToolsRedistDir=C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Redist\MSVC\14.36.32532\ VCToolsVersion=14.36.32532 VisualStudioVersion=17.0 VS140COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\ VS170COMNTOOLS=C:\Program Files\Microsoft Visual Studio\2022\Community\Common7\Tools\ VSCMD_ARG_app_plat=Desktop VSCMD_ARG_HOST_ARCH=x64 VSCMD_ARG_TGT_ARCH=x64 VSCMD_VER=17.6.0 VSINSTALLDIR=C:\Program Files\Microsoft Visual Studio\2022\Community\ windir=C:\WINDOWS WindowsLibPath=References\CommonConfiguration\Neutral WindowsSDKLibVersion=winv6.3\ WindowsSDKVersion=\ ZES_ENABLE_SYSMAN=1 __DOTNET_ADD_64BIT=1 __DOTNET_PREFERRED_BITNESS=64 __VSCMD_PREINIT_PATH=C:\Users\cttc\ODjnavarro\jnavarro\Dev2\ADAtools\installer\deployment\bin;C:\Program Files\Microsoft SQL Server\150\Tools\Binn\;C:\Program Files\dotnet\;C:\Users\cttc\AppData\Local\Microsoft\WindowsApps;C:\Users\cttc\AppData\Local\Programs\MiKTeX\miktex\bin\x64\
If you take a look to the INCLUDE variable, you'll see that its contents is exactly the same that I presented in screenshot showing the "C++ Code Model Inspector - Qt Creator" a few posts before.
So, if MSCV 2022 does not include the complete list of include directories to look for when executing vcvars64.bat, Qt will never be able to learn where are they!!!
Obviously, after installing Qt I've got exactly the same results: the list of folders to look for headers is, once more, the one reported in the said image, so my code does not compile.
Curiously, compiling a simple C++ program using any of the offending headers (such as "math.h" or "string.h" using MSVC 2022 instead of Qt works without problems.
So, having arrived to this point, I'm afraid there is nothing else I can do to solve the problem. My only guess is that, maybe, it is possible, somehow, to add manually the missing paths to Qt creator, but a quick Google search seems to contradict me. The usual answer is "you can't add MSVC manually, it must be autodetected".
Any ideas from the experts?
Thanks.
-
Oh, my God.
I have installed MSVC 2022 in my wife's laptop, which has never seen a compiler in its life, and there the INCLUDE variable is perfect, listing all the necessary paths located in c:\Program Files (x86)\Windows Kits\10\Include\10.0.22000.0* (the ones my laptop does not have).
So, by some unknown reason, when I try to install MSVC 2022 in MY laptop, something goes wrong in spite of all the cleaning made.
I know that this goes beyond the scope of this forum but, any ideas about what to do so the MSVC 2022 installer thinks that it's working in a brand new computer, with no history behind that might lead to this undesirable problem???
Thanks.
-
Maybe Repair Visual Studio helps somehow. 🤞
-
@bleriot13 said in QtCreator reports lots of headers as "not found":
any ideas about what to d
Yes: how about asking your wife to do the programming for you? ;-)
Sorry, couldn't help it.Very difficult to help with this remotely. If necessary/just for testing, why don't you set your machine's INCLUDE or whatever to be the same as hers?
-
@JonB Unfortunately, none of your two suggestions will work. First, programming is not exactly the kind of activity my wife would choose to make a living :-) so I discarded this solution immediately.
Concerning the second one, the INCLUDE variable is set by a chain of batch files, since QtCreator uses these to retrieve the value of this and others environment vars. Changing these batch files is firstly difficult and secondly undesirable, since any update of the underlying MSVC 2022 compiler will restore these.
At any rate, thanks for trying. I know that helping remotely is complicated.
-
@cristian-adam This is what I'm doing right now, but I have no faith on this working at all. I'm starting to consider reinstalling Windows... :-(