The C++ Compiler cannot run a simple test program
-
Hello, I am new to Qt and I just tried to install it for a final project of mine and tried to run the starting program but when i tried to run it it gave me an error. It says that The C++ Compiler cannot run a simple test program
as shown here
I've been trying to get a solution to this for a few hours by now and to no avail found an answer I was looking forHere is the error log
I have tried to uninstall and redownloading multiple times and it always resulted in the same thing but when I tried downloading it on my friend laptop it seems to be working fine as intended. The problem is only on mine.
Is there any solution to this?
-
@cristian-adam
so I reinstalled windows and mingw works
msvc said its missing cxx compiler path but hey atleast mingw works so I guess problem solved
my windows is the problem after all. Had to sacrifice my files but as long as it works its a win in my book. -
@Daemonitas
This error message is usually caused by a permission issue. You can try running QtCreator as an administrator or check if the file is locked by another process. -
@Daemonitas said in The C++ Compiler cannot run a simple test program:
I even tried putting the project in the same drive as Qt but it's also showing the same error
thats totally unrelated to what I suggested.
it still doesn't work.
I take your word for it.
@Daemonitas said in The C++ Compiler cannot run a simple test program:
The build button has been disabled ever since I installed Qt
that you didn't mention, nor show in your screenshot!
open the qtCreator settings/preferences and select the kits tab.
Hover with your mouse over detected kit, it probably has a yellow warning triangle or a red ! in a circle.
A tooltip will popup telling you what issues there are with your kits. Try to fix those
-
@Daemonitas interesting, I did not expect that :D
what tool tip do you get when you hover over "untitled6" in your project settings
or when you select "Project" on the left hand menu bar?
-
At first I thought that the whitespace in the project directory path could pose an issue.
I've tested locally and worked fine.
Which CMake version are you using?
The missing build type configuration like Debug or RelWithDebInfo means that CMake didn't export the project configuration in json file format.
-
@cristian-adam
I'm using CMake 3.24.2
-
Everything looks fine! There shouldn't be a reason why
ninja
would fail.I have a similar setup, and the only visible difference is that I use:
c:\Projects\C++
as a very short path.Do you have
LongPathsEnabled
underHKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem
? As per MSDN: Maximum Path Length Limitation.Any special antivirus program running?
My next approach would be to try from a
cmd.exe
Window the same commands that Qt Creator is doing, for MinGW it should be easier:$ set PATH=C:/Qt/Tools/CMake_64/bin;C:/Qt/Tools/mingw1120_64/bin;C:/Qt/Tools/Ninja;C:/Qt/6.5.0/mingw_64/bin;%PATH% $ cmake --version $ ninja --version $ gcc --version $ moc --version $ cd D:/programm/C++ Homework Sem 2/untitled6 $ cmake -S . -B build -DCMAKE_PREFIX_PATH=C:/Qt/6.5.0/mingw_64 -DCMAKE_BUILD_TYPE=Release $ cmake --build build
-
@cristian-adam said in The C++ Compiler cannot run a simple test program:
Do you have LongPathsEnabled under HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem ? As per MSDN: Maximum Path Length Limitation.
I just enabled it in Registry editor
@cristian-adam said in The C++ Compiler cannot run a simple test program:
Any special antivirus program running?
Just windows defender
@cristian-adam said in The C++ Compiler cannot run a simple test program:
moc --version
Tried to run this in cmd but it appears that i don't have it on my laptop since it said that it is not recognized as an internal or external command
@cristian-adam said in The C++ Compiler cannot run a simple test program:
cmake -S . -B build -DCMAKE_PREFIX_PATH=C:/Qt/6.5.0/mingw_64 -DCMAKE_BUILD_TYPE=Release
apparently I do not have this "CMakeList.txt." its looking for
@cristian-adam said in The C++ Compiler cannot run a simple test program:
$ cmake --build build
and this one resulted in an error too
-
CMakeLists.txt
is the project file for your CMake project.You tried to configure the
untitled6
in the wrong directory, your home directoryC:\Users\-redacted-
.Make sure you go to the project:
$ d: $ cd "D:/programm/C++ Homework Sem 2/untitled6" $ dir $ cmake -S . -B build -DCMAKE_PREFIX_PATH=C:/Qt/6.5.0/mingw_64 -DCMAKE_BUILD_TYPE=Release
cmake -S .
means that CMake should look in the current directory for theCMakeLists.txt
.I assume that you have the
untitled6
CMake Qt project atD:/programm/C++ Homework Sem 2/untitled6
, but you can use any other project.Regarding
moc --version
, where do you have Qt 6.5.0 for MinGW installed? It should be underC:/Qt/6.5.0/mingw_64/bin
The whole exercise here is to get extra information by doing things manually, step by step.
-
@cristian-adam
alright now it shows
looks like I'm missing some packages (?) -
@Daemonitas Have you installed MSVC compiler together with MINGW? This picture shows that cmake try to config a MINGW Qt with MSVC 19.35.
Try to remove MSVC options from PATH, or run full-path CMAKE from Qt directory.
-
@Daemonitas you got the part with the project directory but skipped the other steps that I've provided:
$ set PATH=C:/Qt/Tools/CMake_64/bin;C:/Qt/Tools/mingw1120_64/bin;C:/Qt/Tools/Ninja;C:/Qt/6.5.0/mingw_64/bin;%PATH% $ cmake --version $ ninja --version $ gcc --version $ moc --version
Here I'm adding CMake, MinGW GCC, Ninja and Qt 6.5.0 build for MinGW to the
PATH
environment variable.Then I call the executables to make sure that they are available.
All of them should be available and provide the expected version numbers.
If you don't have
moc
then the path to your Qt MinGW installation is not correct, and you would need to adjust it.When this is OK, then you can go to the project directory and issue the CMake command and build the project.
Edit: Oh, right. The CMake command had one important part missing, the Generator. Sorry about that:
$ cmake -S . -B build -G Ninja -DCMAKE_PREFIX_PATH=C:/Qt/6.5.0/mingw_64 -DCMAKE_BUILD_TYPE=Release
By default CMake would pick the Visual Studio generator and that one ignores any MinGW compiler paths 🙂
-
Here is the entire thing
(I downloaded Qt Version 6.4.3)
Beforehand I downloaded Version 6.5.0 but I thought downgrading would do something -
@Daemonitas This should have worked! The tools are present, can be started, have the right versions.
What happens if you disable the real-time checking of Windows Defender?
You could try with
-G "MinGW Makefiles"
instead of-G Ninja
as CMake generator. But this should fail in a similar way.I assume the installation of MinGW was not corrupted, or that the system has disk failures. Something prevents the compiler to work properly.
What happens if you try it out with a
hello.cpp
?#include <iostream> int main() { std::cout << "Hello C++ World\n"; }
with:
$ g++ hello.cpp -o hello $ hello
If this works then the compiler is fine.
-
@cristian-adam
Compiler is working as intended@cristian-adam said in The C++ Compiler cannot run a simple test program:
You could try with -G "MinGW Makefiles" instead of -G Ninja as CMake generator. But this should fail in a similar way.
as for this yeah it results in an error
and disabling windows defender also didn't solve it
-
@Daemonitas
I am dropping in on this thread rather late, so I may be missing something. But in the example you show works you useg++
as command, why are you usingc++.exe
in the stuff which fails? -
@JonB
for the example that works I just copied what @cristian-adam told me to try outill try using "c++"
edit:
it also works