I have read the question Can I use Qt without qmake or Qt Creator? which is basically the same for Linux, and very useful.
How to compile a basic program using QtCore (console application, even without GUI) on Windows, without using qmake or qtCreator IDE, but just the Microsoft VC++ compiler cl.exe?
For example, let's say we have:
#include <iostream>
#include <QtCore>
int main()
{
QVector<int> a; // Qt object
for (int i=0; i<10; i++)
a.append(i);
std::cout << "hello";
return 0;
}
Using:
call "C:\path\to\vcvarsall.bat" x64
cl main.cpp /I D:\coding\qt\qtbase-everywhere-src-5.15.5\include
fails with:
D:\coding\qt\qtbase-everywhere-src-5.15.5\include\QtCore\QtCore(3): fatal error C1083: Cannot open include file: 'QtCore/QtCoreDepends': No such file or directory
Indeed this file is not present in the release qtbase-everywhere-opensource-src-5.15.5.zip from https://download.qt.io/archive/qt/5.15/5.15.4/submodules/.
TL;DR: More generally, which cl.exe arguments should we use to to able to use all Qt includes, and effectively compile such a minimal project using QtCore?
I finally managed to do it 100% from command line, without the qtCreator IDE, but not yet without
qmake. Steps to reproduce:Let's assume Microsoft MSVC 2019 is installed.
Install
qt-opensource-windows-x86-5.14.2.exe. (This is the latest Windows offline installer I could find), double check that you install at leastmsvc2017_64.Note: Don't use
qtbase-everywhere-opensource-src-5.15.4.zip: using theincludesubfolder from this package forcl.exe /I ...is not enough. (I thought it would, at first)Create a folder
examplecontaining themain.cppfile aboveOpen a command line window in this folder and do:
Now either do
"c:\path\to\msvc2017_64\bin\qmake.exe" -projectto create aexample.proproject file or create it manually with:Do
"c:\path\to\msvc2017_64\bin\qmake.exe". This will create aMakefilefile.Run
nmake. This is Microsoft MSVC's equivalent of themaketool.Copy
c:\path\to\msvc2017_64\bin\Qt5Core.dllinto thereleasefolderRun
release\example.exe. Working!Addendum: here is solution now for a minimal GUI app:
main.cppqt_example_gui.proDo the
vcvarsall.bat x64,qmake,nmakelike in the solution above. No be sure you have this file structure:Run the .exe, that's it!