Building Qt from source on Windows



  • Linux is my development platform, but I need to package my application for Windows, too. I need to build Qt from source (with -static flag).

    However, I've spent 2+ weeks trying to build Qt on Windows 7, without any success. I followed many tutorials and documents, tried VS, msys2, mingw, options A and B, ... - I lost track of all my attempts. But, each one failed somewhere.

    Has anybody recently built Qt (5.5.0+) from source on Windows 7? If so, which installation instructions should I follow? Happy to start from scratch, slight preference with linux-like tools (rather than VS), but would accept anything. Pretty desperate here.



  • Hi. If you feel more comfortable on Linux, why don't you cross compile for Windows? I don't know which distro you have, but there should be a package for mingw-w64, so you can build and deploy from Linux. In theory, after installing the cross compiler, you should just run

    ./configure -xplatform win32-g++ -static ....



  • Hi Leonardo - I tried cross-compiling the application, but that failed too due to some Windows specific optimisation requests. As you said, in theory ...

    Furthermore, the project is very Windows-centric and it does make sense to create a deployment environment on a Windows box.


  • Moderators

    Hi @janeb ,

    I followed many tutorials and documents... I lost track of all my attempts. But, each one failed somewhere.

    Did you fully clean your source tree between each attempt? Stale files will mess up your build. (Note: Commands like make clean don't work)

    I've only done dynamic builds before, and this is all I need to build:

    > cd C:\path\to\source\root\
    > configure.bat -prefix "C:/path/to/lib/output/" -opensource -confirm-license -nomake examples -nomake tests
    > make
    > make install
    

    (If using MinGW, replace make with mingw32-make. If using MSVC, replace make with nmake)

    AFAIK, all you need to do for a static build is add -static to the configure.bat line (although I've never tried this myself). Does that work? If not, post your first few error messages.

    Also, could you describe why you can't use the pre-built dynamic libraries?



  • Hi @JKSH - thanks for your comments.

    There were many attempts and I tried to make each one of them from a clean branch of source code. I did use README (where your instructions I presume are from) from the source archive, I tried MinGW Wiki, ... I haven't tried building from Git yet. All attempts failed at some point, so I asked which set of instructions I should follow in order to build Qt5 from source.

    Anyway, yesterday I cleaned the machine completely and started from scratch. This is what I've done so far:

    This morning, I just tried your instructions

    C:\Qt\qt-everywhere-opensource-src-5.5.1>configure.bat -prefix "C:/Qt/5.5.1/" -opensource -confirm-license -nomake examples -nomake tests
    

    and got an error:

    NMAKE : fatal error U1077: 'if' : return code '0x463'
    Stop.
    Could not find output file 'arch.exe' or 'arch' in C:/Qt/qt-everywhere-opensource-src-5.5.1/qtbase/config.tests/arch : No such file or directory
    WARNING: The DirectX SDK could not be detected:
      There is no Direct X SDK installed or the environment variable "DXSDK_DIR" is
    not set.
    Disabling the ANGLE backend.
    
    WARNING: Using OpenGL ES 2.0 without ANGLE.
    Specify -opengl desktop to use Open GL.
    The build will most likely fail.
    (Press any key to continue...)
    

  • Moderators

    This is not needed unless you want to build Qt WebKit, which is now deprecated. (But if you want Qt WebKit, you'll need several other dependencies)

    I'd recommend installing Visual Studio 2013 Express (or Community Edition) instead. Windows SDK 7.1 is very old.

    NMAKE : fatal error U1077: 'if' : return code '0x463'
    Stop.
    Could not find output file 'arch.exe' or 'arch' in C:/Qt/qt-everywhere-opensource-src-5.5.1/qtbase/config.tests/arch : No such file or directory
    

    You might have better luck using a 32-bit compiler.

    If you still get this error after switching to Visual Studio 2013, and you want to use a 64-bit compiler, see https://bugreports.qt.io/browse/QTBUG-47118 for clues,

    WARNING: The DirectX SDK could not be detected:
    There is no Direct X SDK installed or the environment variable "DXSDK_DIR" is
    not set.
    Disabling the ANGLE backend.

    WARNING: Using OpenGL ES 2.0 without ANGLE.
    Specify -opengl desktop to use Open GL.

    What is your graphics card? If yours supports OpenGL, try its suggestion and add -opengl desktop to your configuration options. (If your graphics card doesn't support OpenGL, you'll need to install the DirectX SDK)



  • Hi. In that case, here's my receipt:

    In my experience, compiling with OpenGL support using mingw-w64 is a bad idea. Its support for the windows API is good, but not as good as Visual Studio's one. Using VS requires little to no knowledge of it. Just download and install the community version.

    Another point is that apparently the configure script is still based on the old DirectX SDK. I might be wrong, but here's how I got it to work. Download DirectX SDK. No need to install. Just extract the exe's content, let's say, to C:\DXSDK .

    After installing Visual Studio, you'll have a shortcut named "Developer Command Prompt for VS2015" in your start menu. Open it. It's different from a normal prompt, as it has most tools from VS already in the PATH variable. Now, start compiling:

    SET DXSDK_DIR=C:\DXSDK
    configure.bat -platform win32-msvc2015 -static ....

    And that's all.



  • Hi @JKSH, @Leonardo,

    Many thanks for your tips and apologies for delay. I got distracted by another task, but will get back to this one again.

    Just to report what happened so far. All my attempts on one machine failed. Switching to another computer I managed to to statically build Qt and Qt Creator once (using your receipts), but failed to reproduce that again. I'm putting all this down to my inexperience on Windows platform. However, I have learnt a lot and I'll get back to this problem again.

    BTW, working with VS is not as scary as it originally looked :-). Once I managed to install it, that is. The installation of VS was a pain as due to my inexperience and some bugs. E.g. installing VS via RDC produces a transparent window - I waiting for hours for something to happen, then tried another version of VS, ...

    Best,
    J.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.