Results 1 to 8 of 8

Thread: Can a Qt program compiled on Linux run on windows?

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Can a Qt program compiled on Linux run on windows?

    Hi there guys, Can a Qt program compiled on Linux run on windows without having to recompile it on Windows. The problem is that I am using Linux because its easier to install and use external libs on Linux than it is on Windows. The problem is that this program is meant to run on a windows platform when its done. So I was wondering if I have to recompile the program on Windows to get it to work there, because if that's the case, I am still going to face the same lib linking problems on windows when all is done. Is there a way to compile the program on Linux (i.e. Ubuntu) is such a way that the .exe file can just run on Window without any need to recompile it on Windows?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,529
    Thanks
    253
    Thanked 722 Times in 712 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Can a Qt program compiled on Linux run on windows?

    Can a Qt program compiled on Linux run on windows without having to recompile it on Windows.
    No. A program built on a linux platform links to the linux runtime libraries, which aren't present on Windows.

    Is there a way to compile the program on Linux (i.e. Ubuntu) is such a way that the .exe file can just run on Window without any need to recompile it on Windows?
    Yes. To build a program on linux which runs on Windows, you need to use a cross-compiling tool chain which builds code with links to Windows run-times. See this blog post, for example. It's an old post but the principles remain the same even if the compiler versions have been updated and the links in the article don't work.

    Remember that you will also need to build Qt and all of the other third-party libraries you use with this cross-compiling tool chain, since the linux versions of these libraries installed on your PC won't be compatible and can't be linked to a cross-compiled executable.
    Last edited by d_stranz; 12th March 2017 at 18:58.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can a Qt program compiled on Linux run on windows?

    Hello,

    as already mentioned, you have to install a cross compile toolchain on Linux for compiling for Windows. Depending on the Linux distribution you use you can install precompiled libraries and tools for Qt and a lot of other libraries you use. As an example, using openSuse Leap 42.2, you can get complete development environments for 32 bit or 64 bit Windows compiles with Qt. So check if there are ready to install packages for your distribution before trying to compile everything yourself.

    If you want to use Mingw64 for windows, getting the precompiled Qt binaries is much more simple than compiling Qt 64 bit under Windows yourself.

    Best regards
    ars

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,529
    Thanks
    253
    Thanked 722 Times in 712 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Can a Qt program compiled on Linux run on windows?

    If you want to use Mingw64 for windows, getting the precompiled Qt binaries is much more simple than compiling Qt 64 bit under Windows yourself.
    I haven't tried this myself so I don't know the answer. Can you install the precompiled Mingw64 binaries on a Windows PC, then simply copy the .lib files over to the linux PC for linking? Or do you actually need to build it all using the cross-compiler toolchain? As you say, building Qt so it comes even halfway close to a prebuilt binary distribution is a major task.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  5. #5
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can a Qt program compiled on Linux run on windows?

    Hello,

    I think I wasn't clear enough in my previous post. So let's try again.

    I'm compiling my applications for both Linux 64 bit and Windows 64 bit. For Windows I'm using MinGW64. Unfortunately the precompiled 64-bit Qt development environment for Windows is only available for Microsoft compiler and thus cannot be used with MinGW64. Therefore one has to download the Qt sources and compile them with MinGW64 for getting a 64 bit development environment under Windows. This is a time consuming work.

    When cross-compiling for Windows 64 bit it is much easier to get a development environment: Just install what you need from the distribution repositories. There is no need to cross-compile Qt sources. For cross-compiling the application you only have to take care that the cross compiler and the corresponding libraries are used. In a project at work I set up the build environment to even include the generation of a Windows installer (using nsis). I then only had to copy the installer to a windows machine, run it there and test my application.

    Can you install the precompiled Mingw64 binaries on a Windows PC, then simply copy the .lib files over to the linux PC for linking?
    I'm not sure if I understand this correctly. Why should we copy the library files from a Windows MinGW64 installation to linux? On linux I get a cross compiler MinGW64 together with all cross compiled libraries. Using these libraries we are sure that all things are compatible. I can only think of one scenario where this might be useful: Assume we need to use a Windows library for which we only have the binary and the header files, but not the library sources. I have no idea if it is possible to link this library under linux (haven't tried it).

    Best regards
    ars

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,529
    Thanks
    253
    Thanked 722 Times in 712 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Can a Qt program compiled on Linux run on windows?

    So I'm still confused.

    Unfortunately the precompiled 64-bit Qt development environment for Windows is only available for Microsoft compiler and thus cannot be used with MinGW64.
    So if you can't get that, then how can you do this:

    When cross-compiling for Windows 64 bit it is much easier to get a development environment: Just install what you need from the distribution repositories.
    If there is no pre-built Mingw64 version of Qt for Windows, then what is there to download and from which repositories besides the cross-compiler and the libraries it provides?

    For cross-compiling the application you only have to take care that the cross compiler and the corresponding libraries are used.
    Right. In order to build a Windows EXE, you must link to the Windows / Mingw64 versions of the Qt link-library .LIB files (which correspond to the .DLL files the app will load when it actually runs on Windows). Which is why I asked if you could:

    simply copy the .lib files over to the linux PC for linking?
    instead of building the Qt link libraries (and DLLs) on linux using the cross-compiler. A binary file is a binary file, so the linker shouldn't care if you built it on linux using the cross-compiler or on Windows using the native Mingw64 compiler.

    Of course, if there is no Mingw64 for Qt on Windows then it is a moot point, but the same principle should apply no matter which library you need to link to.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  7. #7
    Join Date
    Oct 2009
    Location
    Germany
    Posts
    120
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Can a Qt program compiled on Linux run on windows?

    Hello,

    for Windows there exists MinGW 64 bit compiler. You can download one e.g. from http://http://tdm-gcc.tdragon.net/download. However, this is only the compiler, no precompiled Qt environment. For using Qt with this compiler, you have to compile it yourself.

    For Linux there exists MinGW 64 bit cross compiler, i.e. it is a Linux binary that produces code that runs on Windows. For this cross compiler there also exists a precompiled Qt environment. This consists of the libraries, dlls, ... for Windows. These libraries are used by the linker of the cross compiler tool chain to produce the Windows exe file. So on Linux I do not have to compile the Qt cross environment myself. I just install it from the repositories.

    Which is why I asked if you could:

    simply copy the .lib files over to the linux PC for linking?
    instead of building the Qt link libraries (and DLLs) on linux using the cross-compiler.
    Where do you get the .lib files for Qt from? I couldn't find any pre-compiled Qt environment compatible with MinGW64. So what would you want to copy to Linux?

    Again: I do NOT need to compile the Qt libraries and dlls on Linux. They are provided by the Linux repositories. As an example, I have installed the 32 bit environment in a VM running Linux, and it gives me the following files for Qt:
    Qt Code:
    1. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtCore4.dll
    2. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtDBus4.dll
    3. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtDeclarative4.dll
    4. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtMultimedia4.dll
    5. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtNetwork4.dll
    6. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtTest4.dll
    7. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtXml4.dll
    8. /usr/i686-w64-mingw32/sys-root/mingw/bin/QtXmlPatterns4.dll
    9. /usr/i686-w64-mingw32/sys-root/mingw/lib/qt4
    10. /usr/i686-w64-mingw32/sys-root/mingw/lib/qt4/plugins
    11. /usr/i686-w64-mingw32/sys-root/mingw/lib/qt4/plugins/accessible
    12. ...
    To copy to clipboard, switch view to plain text mode 
    Same is available for mingw64 and Qt5, but currently I do not have it installed in my VM.

    Of course, if there is no Mingw64 for Qt on Windows then it is a moot point, but the same principle should apply no matter which library you need to link to.
    As a summary: MinGW64 is running on Windows producing Windows 64 bit exe files. There are no Qt binaries bundled with this compiler.

    Best regards
    ars

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,529
    Thanks
    253
    Thanked 722 Times in 712 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Can a Qt program compiled on Linux run on windows?

    OK, I did not understand that there was a Mingw64 cross-compiler and a cross-compiled Qt distribution available on linux platforms.

    Where do you get the .lib files for Qt from?
    You get them from your Windows build of Qt using Mingw64 for Windows. This was said under the assumption that the only way to get a Mingw64-compiled version of Qt was to build it yourself, either on Windows with the native Mingw64 compiler or by cross-compiling on linux using the Mingw64 cross-compiler. In either situation, the .lib and .dll files had better be the same, and so you could either 1) copy the .lib files from Windows (if you built Qt there) to linux for linking (via the cross-compiler) or 2) copy the dlls from linux (if you built or installed Qt there) to Windows for execution.

    BUT, if the Qt lib and dll files are available in lunix repositories in cross-compiled form, then of course none of this is needed. I simply asked if copying the files was possible in case there was nothing there on linux already. I didn't know the answer.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 5
    Last Post: 12th July 2014, 04:07
  2. Replies: 2
    Last Post: 5th October 2010, 08:20
  3. Replies: 3
    Last Post: 20th September 2010, 22:36
  4. Replies: 13
    Last Post: 10th June 2009, 01:56
  5. Program in Windows, Deploy in Linux
    By suitto in forum Installation and Deployment
    Replies: 1
    Last Post: 8th April 2009, 13:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.