📜 ⬆️ ⬇️

Cross-compiling Qt-4.8.0 under mingw32 (x86) in Gentoo (x86_64)

image
There is no need to install Qt in advance on the target system, no need to pull pre-compiled libraries for Windows.

I did this trick on two platforms, on Gentoo x86_64 installed on VitualBox with KDE 4.8 shell and Qt libraries, and on Gentoo x86_64 home server (Intel® Core (TM) i5 CPU 760 @ 2.80GHz) without any graphical shell and without Qt pre-installed libraries.

Cross-compiler configuration

In principle, the following utilities will be needed for cross-compiling:
And packages:I give an example for Gentoo, I think that for other distributions there may be similar instructions for installing and configuring ming32 (x86).

For the Gentoo distribution, the installation of the cross-compiler is simple:
')
If app-portage / layman is not installed, you need to do the following:

# emerge layman
# mkdir /usr/local/portage
# echo 'PORTDIR_OVERLAY=”/usr/local/portage/”' >> /etc/make.conf
# echo 'source /var/lib/layman/make.conf' >> /etc/make.conf
# env-update


To install the mingw32 cross toolchain:

# emerge crossdev portage-utils
# crossdev -t i686-pc-mingw32


At least three things are connected with compiling 4.8.0:
  1. Without zlib the project will not gather
  2. Project will not build without libiconv
  3. There is a bug associated with the support of tablets
Building and installing the necessary libraries

I did not use the i686-pc-mingw32-emerge utility for three reasons:
! Attention! This assembly for PREFIX = i686-pc-mingw32-, the name of the compiler and utilities on another system may differ. Accordingly, the root directory for this build is the / usr / i686-pc-mingw32 directory, and accordingly all include files and lib files are installed in / usr / i686-pc-mingw32 / usr / include, / usr / i686-pc-mingw32 / lib .


I collected in my home folder, we will need root rights only for installing libraries.

Install zlib:

$ cd
$ wget www.zlib.net/zlib-1.2.6.tar.gz
$ tar -zxf zlib-1.2.6.tar.gz
$ cd zlib-1.2.6
$ CC=i686-pc-mingw32-gcc LDSHARED=i686-pc-mingw32-gcc CPP="i686-pc-mingw32-gcc -E" AR=i686-pc-mingw32-ar RANLIB=i686-pc-mingw32-ranlib ./configure --prefix=/usr/i686-pc-mingw32/

# make && make install

Install iconv:

$ cd
$ wget ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
$ tar -zxf libiconv-1.14.tar.gz
$ cd libiconv-1.14
$ ./configure --enable-static --disable-shared --build=x86_64-pc-linux-gnu --host=i686-pc-mingw32 --prefix=/usr/i686-pc-mingw32/ LDFLAGS="-Wl,-elf2flt" CC="i686-pc-mingw32-gcc"

# make && make install


Qt-4.8.0 build

Next, we proceed to build Qt:

$ cd
$ wget download.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.8.0.tar.gz
$ tar -zxf qt-everywhere-opensource-src-4.8.0.tar.gz
$ cd qt-everywhere-opensource-src-4.8.0
$ wget pastebin.com/download.php?i=CAjgyASQ -O qapplication_win.cpp.patch
$ patch -p0 -i qapplication_win.cpp.patch

The meaning of this patch is to fix the bug with QT_NO_TABLET, QT_NO_TABLETEVENT. The point here is that the QT_NO_TABLET flag removes the QTabletDeviceData definition from the qapplication_p.h header file.

#ifndef QT_NO_TABLET
struct QTabletDeviceData
{


Nevertheless, there are 4 lines in the qapplication_win.cpp file that use QTabletDeviceData, so the corresponding places in the code were wrapped in #ifndef QT_NO_TABLET.

Finally, the mkspec file for mingw32:
$ wget pastebin.com/raw.php?i=uPMXC6cD -O qmake.conf

Those who have another prefix for cross-toolkit need to make the appropriate corrections to the file.

After that, copy the file:
$ cp qmake.conf mkspecs/win32-g++/qmake.conf

Customize:
$ ./configure -prefix /usr/i686-pc-mingw32/usr -bindir /usr/i686-pc-mingw32/usr/bin -libdir /usr/i686-pc-mingw32/usr/lib/qt4 -docdir /usr/i686-pc-mingw32/usr/share/doc/qt-4.8.0 -headerdir /usr/i686-pc-mingw32/usr/include/qt4 -plugindir /usr/i686-pc-mingw32/usr/lib/qt4/plugins -importdir /usr/i686-pc-mingw32/usr/lib/qt4/imports -datadir /usr/share/qt4 -translationdir /usr/share/qt4/translations -sysconfdir /etc/qt4 -examplesdir /usr/share/qt4/examples -demosdir /usr/share/qt4/demos -opensource -confirm-license -shared -fast -largefile -stl -verbose -xplatform win32-g++ -nomake examples -nomake demos -release -no-separate-debug-info -exceptions -no-rpath -no-pch -reduce-relocations -arch windows -no-accessibility -no-xmlpatterns -no-multimedia -no-audio-backend -no-phonon -no-phonon-backend -no-svg -no-webkit -no-script -no-scripttools -no-declarative -system-zlib -no-gif -no-libtiff -no-libpng -no-libmng -no-libjpeg -no-cups -no-dbus -no-gtkstyle -no-nas-sound -no-opengl -no-sm -no-xshape -no-xvideo -no-xsync -no-xinerama -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-mitshm -no-fontconfig -no-freetype -no-xinput -no-xkb -no-glib -iconv -no-optimized-qmake -no-openssl -no-qt3support

Compile:
$ make -j$((`cat /proc/cpuinfo | grep processor | wc -l`+1))

On my home server with an Intel® Core (TM) i5 CPU 760 @ 2.80GHz, I gathered quickly enough.

Install libraries and tools:

# make install

For some reason, I did not install qmake in the appropriate directory, I had to copy

# cp bin/qmake /usr/i686-pc-mingw32/usr/bin/qmake

Testing

$ cd
$ cp -r qt-everywhere-opensource-src-4.8.0/examples/tutorials/addressbook addressbook
$ cd addressbook
$ /usr/i686-pc-mingw32/usr/bin/qmake -spec win32-g++
$ make
$ ls part7/release/part7.exe
part7/release/part7.exe


An executable file has appeared.

Then you can test it in wine, but it is better to copy the executable file along with the libraries to a Windows computer for a cleaner experiment. I tested under Windows 7 (x64). If you have samba configured, you can simply copy everything you need into the folder and run it.

$ cp part7/release/part7.exe /var/samba/files/build/
$ cp `find / -name libstdc++-6.dll 2> /dev/null` /var/samba/files/build/libstc++-6.dll
$ cp `find / -name libgcc_s_sjlj-1.dll 2> /dev/null` /var/samba/files/build/libgcc_s_sjlj-1.dll
$ cp /usr/i686-pc-mingw32/usr/bin/*.dll /var/samba/files/build/


Run:



I sincerely hope that you see the same thing and this article is interesting for you.

Libmysql support

Unfortunately, cross-compiling mysql-connector-c pulls on a separate article. You can use pre-compiled libraries and use the following guide - www.qtcentre.org/wiki/index.php?title=Building_the_QMYSQL_plugin_on_Windows_using_MinGW .

Appeal to Gentoo users from a Gentoo user

Most likely in the near future I will take up ebuild for qt-core, but for now I do not have enough time and effort.

Source: https://habr.com/ru/post/139324/


All Articles