How to build Qt 4.8 64 bit with MingW?

To build Qt 4.8 with MingW, you have to use a proper MingW version. The latest MingW won’t build Qt 4.8. You will get weird problems such as “qsimd.cpp:296:23: error: ‘__cpuid’ was not declared in this scope”. You must use a MingW that includes gcc 4.7. gcc 4.8(such as x64-4.8.1-release-posix-seh-rev5) or later won’t work. Mingw with gcc 4.4 does not support building 64 bit app. So, choosing a correct MIngw version is key to build 64 bit version of Qt 4.8.

If you want to add openssl support for Qt 4.8, you need to choose a proper version of openssl. Newer versions of openssl such as openssl 1.1.1 do not work for Qt4.8. You’d better use an older version of openssl such as the last 1.0.2 version(openssl 1.0.2u). Using newer versions of openssl to build Qt 4.8 will produce the following error:

qsslcertificate.cpp:260:68: error: invalid use of incomplete type ‘X509 {aka struct x509_st}’

error: forward declaration of ‘X509 {aka struct x509_st}’

qsslcertificate.cpp:492:29: error: invalid use of incomplete type ‘EVP_PKEY {aka struct evp_pkey_st}’

You need to download the proper Qt4.8 source code. The source code included in the binary installation of Qt libs such as https://download.qt.io/archive/qt/4.8/4.8.2/qt-win-opensource-4.8.2-mingw.exe does not work unless you want to do a in-source build(i.e. enter into the Qt installation directory c:\Qt\4.8.2 and run configure.exe in that directory then mingw32-make; the in-source build will replace the installed binaries with your newly built one, although you can later install the built binaries into another directory specified by the -prefix configure option.) instead of a shadow-build. You will get the error “qabstractanimation.cpp:1057:38: fatal error: moc_qabstractanimation.cpp: No such file or directory”(as a workround, when this error occurs, you can enter into C:\Qt\build64\src\corelib and run “mingw32-make mocables” to generate the missing moc files manually, but there are more building errors such as “moc_qsequentialanimationgroup.cpp:62:29: error: invalid use of incomplete type ‘class QSequentialAnimationGroupPrivate'”, so do not use this source to build.). You should download this one: https://download.qt.io/archive/qt/4.8/4.8.2/qt-everywhere-opensource-src-4.8.2.zip

Unzip the downloaded Qt4.8 source to C:\qt-everywhere-opensource-src-4.8.2\.

make a directory C:\Qt\build64 to do shadow build in it. You may see this article saying “The shadow build directory must be on the same level as the Qt source package.” but I don’t see this problem, i.e., you can do shadow build in any directory.

run a cmd prompt, cd to the shadow build directory, and set the PATH environment variable:

set PATH=C:\mingw64\bin;C:\Strawberry\perl\bin;C:\Qt\build64\bin;%PATH%

Configure(don’t make examples as something is wrong with the examples of the declarative module, which will terminate the build. You can also skip building the demos as it may cost time.)

C:\qt-everywhere-opensource-src-4.8.2\configure.exe -no-webkit -nomake examples -nomake demos -platform win32-g++ -openssl -I C:\openssl-1.0.2u-64bit\include -prefix C:\Qt\4.8.2\64bit > configure.log 2>&1

mingw32-make > make.log 2>&1

You’d better save the configure log and make log as the configure program and mingw32-make do not save the log for you. You may or may not encounter errors during configuring or making but you may want to see the details of configuration and building at later time if something is wrong with your app built with the Qt build. You can use the following command to see the configure/build progress while the output is being saved to the log files:

Get-Content configure.log -Wait -Tail 30

Note that the configure program ask you to press o to confirm the open source option, then you also need to input y to let the configure program continue.

When linking to generate qtguid4.dll, ld.exe may run out of memory:

./tmp\obj\debug_shared\qgraphicsitemanimation.o: file not recognized: Memory exhausted
collect2.exe: error: ld returned 1 exit status
mingw32-make[2]: *** [….\lib\QtGuid4.dll] Error 1

You may wonder why this happens while your system has 4GB,8GB,16GB or more available memory. This is because ld.exe accompanied by your MingW(such as TDM64-gcc-4.7xx or https://sourceforge.net/projects/tdm-gcc/files/TDM-GCC%20Old%20Releases/TDM-GCC%204.8%20series/4.8.1-tdm64-2/gcc-4.8.1-tdm64-2-c%2B%2B.zip/download) is a 32 bit program which has a 2GB memory limit. To overcome the shortage of memory, try to edit the F:\tools\Qt\482build64\src\gui\Makefile.Debug to change (https://stackoverflow.com/questions/11979482/why-is-g-ld-running-out-of-memory, https://sourceforge.net/p/mingw/mailman/message/28487743/)

CXXFLAGS = -g -Wall -frtti -fexceptions -mthreads $(DEFINES)

to

CXXFLAGS = -g -Wall -frtti -fexceptions -mthreads $(DEFINES) -fno-keep-inline-dllexport

and change (https://stackoverflow.com/questions/41144334/compiling-clang-on-a-32-bit-system-fails-because-of-insufficient-virtual-memory)

LFLAGS = -mthreads -shared -Wl,–out-implib,C:\Qt\build64\lib\libQtGuid4.a -Wl,–no-keep-memory -Wl,–reduce-memory-overheads

to

LFLAGS = -mthreads -shared -Wl,–out-implib,C:\Qt\build64\lib\libQtGuid4.a

This lets gcc to consume less memory. If all the above methods still could not help, you may switch to a 64 bit mingw gcc which can use more memory and is compatible for Qt4.8. The built QtGuid4.dll is about 500MB and ld.exe uses about 5GB memory when linking. From this, we can see either Qt is stupid or gcc is stupid, or both are stupid.

mingw32-make install

This command will fail with the errors:

The syntax of the command is incorrect.
Makefile.Debug:213: recipe for target ‘install_target’ failed
mingw32-make[2]: *** [install_target] Error 1

Makefile:46: recipe for target ‘debug-install’ failed
mingw32-make[1]: *** [debug-install] Error 2

makefile:228: recipe for target ‘sub-winmain-install_subtargets-ordered’ failed
mingw32-make: *** [sub-winmain-install_subtargets-ordered] Error 2

So before installing, please edit the C:\Qt\build64\src\winmain\Makefile.Debug to change the line

@$(CHK_DIR_EXISTS) C:$(INSTALL_ROOT)/Qt/4.8.2/64bit/lib/pkgconfig $(MKDIR) C:$(INSTALL_ROOT)/Qt/4.8.2/64bit/lib/pkgconfig

to

@$(CHK_DIR_EXISTS) C:$(INSTALL_ROOT)\Qt\4.8.2\64bit\lib\pkgconfig $(MKDIR) C:$(INSTALL_ROOT)\Q\4.8.2\64bit\lib\pkgconfig

After the installation, the Qt binaries are still unavailable. You should copy the dlls libgcc_s_sjlj-1.dll and libstdc++-6.dll from the Mingw installation directory(mingw/bin/) to the Qt installation directory(Qt/4.8.2/bin64/).

Here is a guide to use jom to build Qt4.8.

 

Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:

Leave a Reply