Cross compiling Qt application for Windows on Linux with dynamic linking
Asked Answered
T

4

14

To comply with Qt's LGPL license, an application using the Qt library must either make the source code available or link dynamically against Qt (if I got that correctly in this few words).

So I'd like to create a closed source application doing exactly that. Additionally, I'd like to develop on Linux (currently Xubuntu 12.04) using g++/MinGW with C++11 support to create windows binaries. I followed this helpful guide to accomplish the latter. But as the guide also states, statically linked executables are created.

Since I used MXE to automatically download and build the Qt library (version 5.0), I didn't have much of a chance to influence the process. So my question is, how do I create dynamically linked versions of the Qt library and respective applications?

Tyrannous answered 28/1, 2013 at 21:37 Comment(2)
One question for this: Why not use mingw on windows? I think mingw cross compiler on linux would support c++11 the same level as on windows.Multitude
@MinLin for me, reason is the more comfortable Linux environmentSyndesmosis
G
10

update

Now the preferable way to build dynamic versions of the libraries with MXE is specifying 'shared' option for the toolchain:

make MXE_TARGETS=i686-w64-mingw32.shared qt5

original

EDIT: I've created a git repository where I've gone through and made all the necessary changes to MXE to build a shared version of qtbase. It's available at https://github.com/jeremysalwen/mxe. To build, clone the repository and then run 'make qtbase'. I've left my original post below.

So I downloaded the mxe environment and it looks like the code used compile qt is help in src/qt.mk

The basic procedure is to match up this code with the standard directions for building qt. If you look inside qt.mk and qtbase.mk you'll see it's actually quite simple, and essentially just runs ./configure, make, and then installs the generated files. If you can look at this, you should be able to match up directions for building qt statically/dynamically and modify qt.mk so that it matches the dynamic directions.

In any case, I think I have found the issue. It looks like the difference is the "-static" flag when compiling qt. So if we simply remove the "-static" flag which is passed to ./configure in qt.mk and qtbase.mk, I would expect that mxe would then build a dynamic qt version. Of course you might need to change other things, but hopefully this is all you need to do.

Gormandize answered 20/2, 2013 at 9:37 Comment(5)
@Tshepang: I've made a github repository where I made the necessary changes to the build scripts for qtbase and all its dependencies. I've added a link to my post.Gormandize
builds well, and so does my app; now I must just figure out how to get this packaged and running on WindowsSyndesmosis
Same here, so thank you very much so far. When running the compiled application in Windows, the dlls are missing at first (of course), but when copying the needed ones all I get is a runtime error. I'll investigate this further.Tyrannous
I am not sure what the next step would be. I see there's a bunch of downloads offered, and the one labeled MinGW 4.7 likely the right one. Do I just install it and all will be well? Is that what you tried @Ratatwisker? I am scared of downloading it, only to find that it doesn't work (it's too big, at 800MB+).Syndesmosis
I tried the ones from the MinGW package as well as the ones from the mxe build (located at <mxe>/usr/i686-pc-mingw32/qt5/lib/). Both ways result in the same message when trying to run the compiled application: "This application has requested the Runtime to terminate it in an unusual way." Using the Visual Studio debugger I can see two messages saying "Invalid parameter passed to C runtime function." The next step I wanted to try is compiling Qt and the application in debug mode, but I didn't have the time to do so.Tyrannous
M
5

First you need to have wine setup.

sudo apt-get install wine

Then download Qt5 Windows MinGW SDK Run with wine

wget http://releases.qt-project.org/qt5/5.0.1/qt-windows-opensource-5.0.1-mingw47_32-x86-offline.exe
wine qt-windows-opensource-5.0.1-mingw47_32-x86-offline.exe

Follow the wizard install Qt. Then

cd ~/.wine/drive_c/Qt/Qt5.0.1/Tools/QtCreator/bin
wine qtcreator.exe

I tried the examples in qtcreator, it compiles and runs well under linux, and when I copy the exe file to a windows machine with Qt set up, it also runs well.

Of course one drawback is that you are not feeling native using qtcreator and the compiler using wine. I don't know how much slower it is compared to native linux binary. But jom is available and you can utilize multiple cores to compile if your project is that big.

To use jom instead of make in qtcreator, modify here in qtcreator.

projects > Build & Run > Build > Build Steps > Make

replace with jom and add make arguments -j N where N is the core numbers you want to use.

Multitude answered 1/4, 2013 at 5:55 Comment(2)
What is jom, and what does offline in the name mean?Syndesmosis
jom is equivalent to make, replace make with jom -j N will start N parallel processes to make you project. offline is just the naming of QtSDK installer, I think it means the installer has everything you need and is able to install qt when you don't have an internet connection.Multitude
D
2

I've been stumbling through this recently and found some success with octave's fork of mxe. He went through the trouble to build qt with shared (.dll) library support which satisfied my needs. Here is a link to his post.

Dari answered 27/3, 2013 at 21:29 Comment(0)
B
1

You need to build QT for dynamic linking. If you have QT built for static linking (usually .a files in linux) your binary will be static. If you build against shared object files (.so) in linux, your binary will be dynamically linked. You will also need to include the relevant .dll's with your application so when someone else runs the executable it has access to those libraries.

The QT SDK from qt-project.org includes the dynamically linked files.

Booking answered 20/2, 2013 at 6:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.