Compiling static Qt for Windows can't open include file - qt

I've been trying to get a static build of Qt 5.7 together so I can start compiling an application statically on Windows, but it's been a bit of a slog. I've got most of the process working - except it is complaining about not being able to include a file now that I can't see any reason for it to complain about.
I have to use MSVC (2015 is what is installed) and nmake because we're including webkit (which is possible with MinGW - and so we can't cross-compile from Linux either).
I've worked through and adapted the following sites (amongst others):
http://amin-ahmadi.com/2016/09/22/how-to-build-qt-5-7-statically-using-msvc14-microsoft-visual-studio-2015/
https://wiki.qt.io/Building_Qt_Desktop_for_Windows_with_MSVC
How do you compile OpenSSL for x64?
My configure command:
configure -debug-and-release -commercial -static -ltcg -accessibility \
-platform win32-msvc2015 -qt-sql-sqlite -qt-sql-sqlite2 \
-plugin-manifests -no-audio-backend -openssl -no-dbus \
-incredibuild-xge -sse2 -qt-style-windows -qt-style-fusion \
-no-native-gestures -qmake \
-I C:\devel\source\openssl\inc64
And right now it's complaining that it can't load "openssl\ssl.h" - except that this is available in C:\devel\source\openssl\inc64\openssl\ssl.h

Related

Qt Quick emulation layer crashed when QtQuick.Controls is imported in QML

My ssd died and I had to reinstall Qt, Im using the same version as before (5.15.2, Qt Creator 6.0.2 and MSVC2019). Described problems appears only while using Static build.
This type (ApplicationWindow) is not supported as a root (Im not 100% sure if it was fine before reinstall)
Invalid property name "title, maximumHeight, maximumWidth, minimumHeight, minimumWidth".
And finally after resolving (Changed from ApplicationWindow to Window, and commented Invalid Properties) these two errors I got: Line 1: Qt Quick emulation layer crashed. I attached a debugger to Qt Creator and it's 0xC0000005 on Editor, Preview and Render.
I tested it in both ways, with latest Qt Creator (installed before making Static kit because it will wipe my Qt directory) and with Qt Creator 6.0.2 (installed after making Static kit).
To compile Static Kit I used this script, but after some problems (jom and jom install did not create any files in QtInstallDir) I just run configure.bat by myself, and then jom and jom install and files were in their place.
The solution can be:
Designing using diffrent kit with Window and then on release change Kit to static, change Window to ApplicationWindow (Im using onClosing from ApplicationWindow).
but it's dirty and I personally do not like it. Is there any other solution?
EDIT: non-static versions are fine (self-compiled and one from MaintenanceTool).
Static configure.bat:
configure.bat -prefix %QTINSTALLDIR% -platform %PLATFORM% -opensource -debug-and-release -confirm-license -opengl dynamic -mp -static -static-runtime -no-shared -qt-libpng -qt-libjpeg -qt-zlib -qt-pcre -no-compile-examples -nomake examples -no-icu -optimize-size -qt-sqlite -openssl-linked OPENSSL_PREFIX=%SSLINSTALLDIR%
Non-static configure.bat:
configure.bat -prefix %QTINSTALLDIR% -platform %PLATFORM% -opensource -debug-and-release -confirm-license -opengl dynamic -mp -no-compile-examples -nomake examples -optimize-size -qt-sqlite
Diffrence:
-static -static-runtime -no-shared -qt-libpng -qt-libjpeg -qt-zlib -qt-pcre -openssl-linked OPENSSL_PREFIX=<location>
Okay, I fixed the Invalid property name .., I dont know what really fixed it but:
I had wrong versions of requirements. I was on latest of Ruby, Python etc.
I installed Submodules one more time using script linked in main post and then installed them one by one by my own hands using qmake then jom clean all then jom install.
Also I found that the Line 1: Qt Quick emulation layer crashed. error appear only when I have QtQuick.Controls <any_version> in imports. Im still trying to fix this.
Fixed. I did this by doing those steps:
In maintenance tool I downloaded Mingw64 and Mingw64 for 5.15.2 and for "Tools".
I did an static mingw build using this powershell script: https://wiki.qt.io/Building_a_static_Qt_for_Windows_using_MinGW
I saw that the script is changing qmake.conf files in mkspecs folder. I ran this MSVC script to make MSVC Static build and after unzipping QtBase I modified qmake.conf in mkspecs/winrt-x64-msvc2019 and in mkspecs/win32-msvc.
QMAKE_LFLAGS += -static
QMAKE_CFLAGS_RELEASE -= -O2
QMAKE_CFLAGS_RELEASE += -Os
DEFINES += QT_STATIC_BUILD
Then the qt setup and qt build command, when build is finished I modified the (THIS TIME IN PREFIX LOCATION / LOCATION WHERE QT STATIC IS INSTALLED) qmake.conf in mkspecs/winrt-x64-msvc2019 and in mkspecs/win32-msvc
CONFIG += static
Run Qt Creator and the Designer is fine.

compile qt 5.12.4 with open ssl static fail

I am trying to compile qt with open ssl statically
I could compile openssl using vs2017 after install perl and configuring it
i used nmake and it worked with -no-shared smoothly.
Then i open the openssl folder and have the following
dll->x64->release>
bin
->c_rehash.pl
->libcrypto-1_1-x64.dll
->libcrypto-1_1-x64.pdb
->libssl-1_1-x64.dll
->libssl-1_1-x64.pdb
->openssl.exe
->openssl.pdb
include
openssl
header files
lib ->libcrypto.lib
->libssl.lib
->ossl_static.pdb
- engines-1_1 -> capi.dll
capi.pdb
padlock.dll
padlock.pdb
Then i opened VS command line
and opened Qt 5.12.4 coder
configure -static -openssl-linked -opengl dynamic -nomake tests -nomake examples -I "T:\openssl\dll\x64\release\include" -L "T:\openssl\dll\x64\release\lib" OPENSSL_LIBS="-lUser32 -lAdvapi32 -lGdi32 -lCrypt32"
I get the following:
error feature 'openssl-linked' was enabled but the pre-condition !features.securetransport && libs.openssl' failed

Qt -sysroot, -prefix, -extprefix and -hostprefix options

What is the correct way to use -prefix -extprefix and -hostprefix options to cross compile Qt5?
I have sysroot dir for my arm board. And I have no problems with cross compiling Qt for ARM except one - I can't figure out how to specify installation path to directory on my host machine (not whitin sysroot). Every combination of -[..]prefix flags trying to install Qt on board. There is not much disk space on board, so I want install Qt locally.
It's my current config:
./configure -opengl es2 -nomake tests -no-libjpeg -skip qtwebkit -skip qtwebkit-examples -no-xcb -device linux-jetson-tk1-g++ -device-option CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- -sysroot /mnt/jetson_tk1_sysroot -hostprefix /home/alan/work/qt/qt_5.5.1_arm_cross_compiled -make libs -debug -v
I'm already read this SO topic, Qt docs and google a lot.
I'm running Ubuntu on both host and target if it's matter.
Install step targets the directory specified by extprefix which is optional and defaults to sysroot/prefix. Defining extprefix to point some directory in the host should prevent you from polluting your sysroot. hostprefix allows separating host tools like qmake from target binaries. When given, such tools will be installed under the specified directory instead of extprefix.
Using these prefix flags keeps your sysroot clean and separates device binaries and host tools:
export INSTALLPATH=/home/alan/work/qt/qt_5.5.1_arm_cross_compiled
./configure ... -extprefix $INSTALLPATH/binaries -hostprefix $INSTALLPATH/tools

Build Qt (static linking) for Visual Studio 2017 32bits

On my Windows 7 SP1 machine I would like to use Qt in Visual Studio and compile Qt projects with Visual Studip with static linking,to be able to share my projects in a single .exe file.
Since there are no precompiled libraries for Visual Studio 2017 32bits (although they exists for x64),i'm going to compile Qt from sources.
Following Qt's documentation,I started by installing Python 2.7.13 and Active-Perl,and adding their installation path to the PATH variable,along with the gnuwin32/bin folder
Then i created a qt5vars.cmd file under C:\Qt,here's his content :
REM Set up \Microsoft Visual Studio 2017, where <arch> is \c amd64, \c x86, etc.
CALL "C:\Program Files\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86
SET _ROOT=C:\Qt\5.9.1
SET PATH=%_ROOT%\qtbase\bin;%_ROOT%\gnuwin32\bin;%PATH%
REM Uncomment the below line when using a git checkout of the source repository
#REM SET PATH=%_ROOT%\qtrepotools\bin;%PATH%
SET _ROOT=
And finally I unzipped Qt sources (downloaded from here to C:\Qt\5.9.1,and jom under C:\Qt\jom
I'm planning to use these commands (after executing qt5vars.cmd) to compile and install Qt :
configure -debug-and-release -opensource -platform win32-msvc2017 -static -nomake examples -nomake tests -prefix C:\Qt-5.9.1
jom -j 2
jom install
I already installed Qt vs tools in VS2017.
Is the procedure correct,or should I change something ? (particularly in the configure command)
Looks good. My only remarks would be:
To remove gnuwin32 path as I don't see a reason why would you need it.
And consider making a shadow build to keep Qt sources unpolluted.
set _SHADOW_DIR="C:\build_static"
set _SOURCE_DIR="C:\SrcQt5.9.1"
...
cd %_SHADOW_DIR%
call %_SOURCE_DIR%\configure ...
Run: "x86 Native Tools Command Prompt for VS 2017"
Or from console
%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
Go to your Qt source dir "qt-everywhere-src-5.14.0/"
Run
configure -static -debug-and-release -prefix "f:\Qt\Static\build\5.14\build" -platform win32-msvc -qt-zlib -qt-pcre -qt-libpng -qt-libjpeg -qt-freetype -opengl desktop -qt-sqlite -sql-odbc -no-openssl -opensource -confirm-license -make libs -nomake tools -nomake examples -nomake tests -skip qtwebengine
After some hours run
nmake
Wait some hours again and run
nmake install
A lot of post about qtwebengine,ssl i simply disable this.
Hope this post help you save your expensive time.

Raspberry Pi 2 and Qt 5.7 - make stuck at `../qtbase/bin/qmake -conf ../qtbase/qt.conf -o Makefile qt.pro`

I trying to compile a native build of Qt 5.7 (I've yet to do a cross-compilation of that thing...) on the Raspberry Pi 2. I have followed the tutorial on the official Qt wiki. The configure step I have is:
./configure -v -opengl es2 -tslib -force-pkg-config -device linux-rasp-pi-g++ -device-option CROSS_COMPILE=/usr/bin/ \
-opensource -confirm-license -optimized-qmake -reduce-exports -release -qt-pcre -make libs \
-prefix /usr/local/qt5 2>&1 | tee config.out
And my setup is similar to the one in the tutorial - I'm using an external USB stick with ext4 file system mounted at /media/USB and that a mount --bind from /media/USB/build/QT_SRC to /opt/QT_SRC. Prerequirements have been installed (including the libxcb-xinerama0 and libxcb-xinerama0-dev which the article points out as necessary for Qt5.6 and later). A !1GB swapfile was added to USB drive too.
After I executed ./configure I did
time make -j3 2>&1 | tee make.out
I've also tried plain make (without support of parallel compilation and linking). The result is the same:
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
...
...
...
/opt/QT_SRC/qtbase/bin/qmake -qtconf /opt/QT_SRC/qtbase/bin/qt.conf -o Makefile qt.pro
This is all that I'm getting. It repeats and repeats itself A LOT OF TIMES and for a LONG PERIOD OF TIME. I wanted to do part of the build while I was sleeping so I just ran make before I went to bed...6.5 hours ago. Now that I'm awake I found this...result. I obviously have the qmake in there otherwise an error would have been triggered but I have no idea what is happening here.
Has anyone tried to build Qt 5.7 on Raspberry Pi 2 and encountered this weird issue?
For some reason the top level configure is not working properly (at least in my case...). I had to go inside qtbase and run it from there. You can follow most of the instructions from the official guide on building Qt 5 natively on the Pi but it appears that not everything will be compiled and installed. The solution of this problem came from this post where it says:
cd to the top level directory of the Qt 5's sources
$ cd QT_SRC_ROOT_DIRECTORY
Choose which modules you would like to build and install and do
$ for module in qtcharts qtdatavis3d qtimageformats qtsvg ...;
> do
> cd QT_SRC_ROOT_DIRECTORY/$module
> QT_SRC_ROOT_DIRECTORY/qtbase/bin/qmake
> make
> sudo make install
> done
This basically loops through each module by going inside, running qmake (that is why you first have to compile what's inside qtbase so that you can have the qmake binary - except for the qtbase all other modules are based on pro files that is Qt project files which can be used only with a qmake tool), then make and finally sudo make install.
I used absolute paths (unlike in the mentioned blog post) since the ../$module inside the for loop didn't actually work but using absolute paths worked like a charm. So in my case I had /opt/QT_SRC as my QT_SRC_ROOT_DIRECTORY so I added it in that loop for accessing each $module. The qmake in my case was at /opt/QT_SRC/qtbase/bin/qmake.
Hope this helps someone else. I now have fully functional Qt 5.7 on my Raspberry Pi 2 including the GPL modules QtCharts and QtDataVisualization. Just tested the touch examples as well as the OpenGL Qt cube example - wonderful!
PS: The documenation on both native and cross-compile builds for the Pi needs serious updates and fixing...And research how to do things properly.
I ran into the same problem building Qt 5.7 on Raspberry Pi 3. I solved it by building and installing all modules individually, starting with qtbase like this:
$ .../qtbase/bin/qmake
$ make
$ make install
The order of building is important. I can't remember the order I followed but, some of the Qt modules yield an error if they need another module built first. Error messages are like this:
Some of the required modules (qtHaveModule(???)) are not available
I didn't build a few modules like qtwayland, qtwebview or qtwebengine because they need some other stuff installed and I don't need them.
After building Qt 5.7 and configuring my Raspberry Pi, I can run all my Qt applications successfully.

Resources